css - Why don't margin-top: auto and margin-bottom:auto work the same as their left and right counterparts? -


if set css margin properties of div so:

div { margin-left: auto; margin-right: auto; } 

i div centered horizontally in page, like so.

however, if change css this:

div { margin-top: auto; margin-bottom: auto; } 

my div not vertically centered. don't need know workaround (plenty of solutions are available) know reason behaviour. why don't margin-top , margin-bottom work in same way? missing?

the short answer spec says so.

10.6.2 inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow , floating replaced elements

if 'margin-top', or 'margin-bottom' 'auto', used value 0.

http://www.w3.org/tr/css2/visudet.html#computing_heights_and_margins


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -