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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:58:33  来源:igfitidea点击:

CSS height: 100% vs height: inherit

css

提问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 inheritor 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: inheritwill, 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: inheritand height: 100%will have the same behaviour for the child.

height: inherit顾名思义,将继承其父级的值。如果父项的值为height: 50%,则子项也将是其父项高度的 50%。如果父级的大小以绝对值定义(例如height: 50px),则height: inherit和 子级height: 100%将具有相同的行为。

回答by benscabbia

height: inheritThe inherit keyword specifies that a property should inherit its value from its parent element.

height: inheritinherit 关键字指定属性应从其父元素继承其值。

height: 100%Defines the height in percent of the containing block

height: 100%定义包含块的高度百分比

For examples, look here

例如,看这里