1

From what I understand, setting height to auto will make it so that the parent container will adjust to the height of the child elements inside. But, isn't that on by default, anyways? Consider, the example below:

#outer {
border: 3px solid red;
height: auto;
}
#inner {
border: 1px solid blue;
height: 300px;
}
<div id = 'outer'>
<div id = 'inner'> inner </div>
</div>

Using or not using height:auto, the parent div still adjust to the height of the child div. In this case, what can we use height: auto on?

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
frosty
  • 2,559
  • 8
  • 37
  • 73
  • `height: auto` is the default setting. It matters a lot when dealing with percentage heights. See this post: [Working with the CSS `height` property and percentage values](http://stackoverflow.com/questions/31728022/why-is-percentage-height-not-working-on-my-div/31728799#31728799) – Michael Benjamin Feb 27 '16 at 17:12

1 Answers1

2

If I understand your question properly, you are asking what is point of using height:auto?

By default height of the div is auto that is why even if you add height:auto or not, it doesn't make any difference. Following link will help you understand this better.

CSS Height

Nitin Garg
  • 888
  • 6
  • 7
  • Can you give an example of an element or two that doesn't have height: auto, on default? – frosty Feb 27 '16 at 16:07
  • If it's on default for EVERY element then what's the point of declaring it at all? – frosty Feb 27 '16 at 16:08
  • @frosty, If you notice you will find that almost every css property is assigned a default value for example display:inline, overflow:visible,height:auto,width:auto etc. If you are from server side programming language I can give you an example from JAVA/.Net. Here when we declare a var of type int, it is by default assigned value "0" but that doesn't mean we cannot/shouldn't assign that value to "0" again. Hope this helps you. – Nitin Garg Feb 27 '16 at 16:24
  • Hmmm. Now that I think about it, I guess you're right. But your comment should be in the answer itself, as it actually answers the main question itself. The current answer doesn't. – frosty Feb 27 '16 at 16:26