CSS 高度:100% vs 高度:继承
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28352873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS height: 100% vs height: inherit
提问by dnc253
I've seen the question asking the difference between height: 100%;
and height: auto;
, but what's the difference between height: 100%;
and height: inherit;
?
我已经看到了问题,问的区别height: 100%;
和height: auto;
,但什么是之间的区别height: 100%;
和height: inherit;
?
I basically want this element's height to fill/match it's container. Would there be a reason to use 100%
over inherit
or vice versa?
我基本上希望这个元素的高度填充/匹配它的容器。是否有理由使用100%
overinherit
或反之亦然?
回答by Nepoxx
height: 100%
will match the height of the element's parent, regardless of the parent's height value.
height: 100%
无论父元素的高度值如何,都将匹配元素父元素的高度。
height: inherit
will, as the name implies, inherit the value from it's parent. If the parent's value is height: 50%
, then the child will also be 50% of the height of it's parent. If the parent's size is defined in absolute values (e.g. height: 50px
), then height: inherit
and height: 100%
will have the same behaviour for the child.
height: inherit
顾名思义,将继承其父级的值。如果父项的值为height: 50%
,则子项也将是其父项高度的 50%。如果父级的大小以绝对值定义(例如height: 50px
),则height: inherit
和 子级height: 100%
将具有相同的行为。