html - CSS: Making nested min-height consistent -
for reason, nested elements min-height
not inherit height of grandparent in browsers.
<html style="height: 100%"> <body style="min-height: 100%"> <div style="min-height: 100%; background: #ccc"> <p>hello world</p> </div> </body> </html>
i haven't bothered testing between different browser versions, in chrome 26 , opera 12.14, displays expect, gray background covering of screen hello world in top left corner.
however, in ie 9 , firefox 20, gray background height of single line of text.
testing further, adding:
position: relative
div changes nothing
min-height: inherit
on div changes nothing
position: absolute
changes width, height
100% in above browsers except ie 9, background covers text.
position: fixed
similar position: absolute
, except ie 9 reverts original behaviour of 100% width.
float: left
similar position: absolute
, except firefox 20 shrinks background cover text.
from http://www.w3.org/tr/css2/visudet.html#the-height-property:
if height of containing block not specified explicitly (i.e., depends on content height), , element not absolutely positioned, value computes 'auto'
is min-height
considered explicit or not? think confusion between browsers. position: absolute
, fixes firefox, , ie 9 has unexpected behaviour (which not unexpected, being ie).
is possible consistent across major browsers?
please not suggest answers require javascript, or body having fixed height. know possible workarounds, isn't i'm trying achieve. using position: absolute
breaks layout pulls element out of flow, , positioning below dynamically sized element, workaround javascript.
firstly, observation:
in chrome 26 , opera 12.14, displays expect, gray background covering of screen hello world in top left corner.
does seem incorrect, in chrome version 26 shows gray background height of single line of text. (just firefox , ie9). believe right according w3 spec quoting from, height of body
containing div
not specified explicitly.
you can display: table
, display: table-row
, display: table-cell
. won't need min-height
@ then. have tested jsfiddle in chrome 26, safari 5.1.7, firefox 20, ie10, ie10 in ie9 mode, ie10 in ie8 mode , renders same in of these browsers, starts break when using ie10 in ie7 mode.
css
html { display: table; height: 100%; width: 100%; } body { display: table-row; } div { display: table-cell; background: #ccc; }
Comments
Post a Comment