How to center a button WITHOUT a div using CSS


Tags: html,css

Problem :

I am trying to center a button without a div. The button is as follows

<body>
  <button>Some Text</button>
</body>

I have tried using a few different techniques such as:

text-align: center

and

margin:0 auto; 

but these don't work.



Solution :

Its simple, just make it display as a block element:

<body>
  <button>Some Text</button>
</body>

button {
    display: block;
    margin: 0 auto;
}

http://jsfiddle.net/df216mho/


    CSS Howto..

    how to create navbar without float?

    How to break a table with CSS diagonally or vertically?

    How to remove href attributes from a tag and remove css associated to it in iframe using jquery

    How to give css sprites effect?

    How to convert template from table to div

    How to darken a background using CSS?

    How can i edit font-size and font-family option in css file using sed?

    How to CSS Display:table grow right

    How to override the CSS !important property when the original file loads after the customized css file

    CSS Flexbox: How do you align child elements of a flexbox container to opposite far ends of the main axis?

    How to set class on div that is inside of repeater in code behind?

    How would I call :parent for this tooltip?

    How to add font to web application .css file

    how to use .css to add an address to the end of every .html page?

    How to apply CSS class to a parent element?

    How does CSS 'overflow:hidden' work to force an element (containing floated elements) to wrap around floated elements?

    How to change parent's CSS only when child is hovered?

    how can i add style with CSS to