Just a quick question that was bugging my mind : Why centering with
margin:0 auto
does work fine with
display:block
but does not center a div when display is set to
display:inline-block
Thanks for answers
Just a quick question that was bugging my mind : Why centering with
margin:0 auto
does work fine with
display:block
but does not center a div when display is set to
display:inline-block
Thanks for answers
My understanding is as follows (though I am happy to be corrected).
You need to learn about inline boxes (not blocks) to see what is happening. An inline box contains inline items such as text and images. An inline block maintains its position within the inline box but acts as a block element within its position inside the box. Just like a word in the text cannot have its own width, neither can an inline block.
The actual spec for line boxes.
See http://www.w3.org/TR/CSS2/visudet.html#Computing_widths_and_margins
Blocks:
Inline-blocks:
I realise that I am a bit late answering this, but you can get around this issue if you want to combine margin auto with inline-block by specifying text align in body as in ...
inline-block
elements don't respect right or left margin, therefor the settingauto
can't be applied.block
elements respect all margins.