Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS height: 100% vs height: inherit

Tags:

css

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;?

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?

like image 918
dnc253 Avatar asked Feb 05 '15 19:02

dnc253


People also ask

Is height inherited CSS?

CSS properties such as height , width , border , margin , padding , etc. are not inherited.

What does height 100% do in CSS?

4 Answers. Show activity on this post. height: 100% gives the element 100% height of its parent container. height: auto means the element height will depend upon the height of its children.

What does HTML height 100% mean?

It just means 100% of the div or class or tag it is enclosed within.

How do you set height to 100% of a parent?

container div has two parent elements: the <body> and the <html> element. And we all know that the default value of the height property is auto , so if we also set the height of <body> and <html> elements to 100%, the resulting height of the container div becomes equal the 100% height of the browser window.


2 Answers

height: 100% will match the height of the element's parent, regardless of the parent's height value.

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.

like image 182
Nepoxx Avatar answered Oct 05 '22 16:10

Nepoxx


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

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

For examples, look here

like image 30
benscabbia Avatar answered Oct 05 '22 15:10

benscabbia