我用这个css设置一个<div>
至最大高度
谁能给我一个一般性的答案,两者有什么区别height: 100%
and min-height: 100%
?
这是 W3C 的解释(link):
The following algorithm describes how the two properties [min-height and max-height] influence the used value of the 'height' property:
The tentative used height is calculated (without 'min-height' and 'max-height') following the rules under "Calculating heights and margins" above.
If this tentative height is greater than 'max-height', the rules above are applied again, but this time using the value of 'max-height' as the computed value for 'height'.
If the resulting height is smaller than 'min-height', the rules above are applied again, but this time using the value of 'min-height' as the computed value for 'height'.
总结一下:基本上,如果最小高度大于其他高度(无论是否指定显式高度),则使用最小高度作为高度。如果最小高度小于原本的高度,则最小高度不起作用。
对于您给出的具体案例,指定height:100%
使元素的高度等于包含块的高度。 (但是,这可能会被否决,例如,如果您还指定max-height:50%
.) 指定min-height:100%
意味着如果计算的高度小于 100%,事实上,即使您明确指定了小于 100% 的高度,它也会被视为您说height:100%
。请注意,一个关键的区别是max-height 可以推翻高度,但不能推翻 min-height(因为根据上面引用的 W3C 建议,最大高度是在高度之后但在最小高度之前考虑的)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)