00 Votes

CSS: Default Value for Height

Question by Compi | 2016-02-16 at 17:56

I have a DIV container to which I have applied a fixed width using the property "height" in an external stylesheet file.

However, there is one HTML page on which I would like to replace this fixed height with the default height of a standard DIV. That means, although I have defined a fixed height within my stylesheet, I would like to read that height via inline CSS for a specific element so that the height is adjusting dynamically to the content as usual.

How can I do that? Sure, it would be easy when we would talk about the width - then I could just overwrite with 100% - but we are talking about the height and here that is not possible. Does someone have any idea?

ReplyPositiveNegative
0Best Answer0 Votes

The default value for height is "auto".

So, you just have to overwrite the height with "height:auto" for the corresponding elements.

CSS:

.fixedheight {
  height: 100px;
}

HTML:

<div class="fixedheight">
  This DIV has a fixed height.
</div>

<div class="fixedheight" style="height:auto">
  This DIV behaves as standard.
</div>

The first DIV in the example has a fixed height of 100 pixels. The second is reset to the default behavior with "height:auto" so that the height fits the content.
2016-02-18 at 17:46

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.