div default height and adaptive height

Source: Internet
Author: User

Turn: This article and we will focus on how to control the div minimum height and div adaptive height problem, if we need to set a div height, when the inside of something above this height, let the container automatically open, that is, div adaptive height. When the information inside is seldom, we set it to a minimum fixed height.


How to control div minimum height and div self-fit height

We often encounter a situation when we use div layout: We need to set a div height, when the inside of something above this height, let the container automatically open, that is, div adaptive height. When the information inside is seldom, we set it to a minimum fixed height.

We know that in IE6, if the height of the child container exceeds the parent container, the parent container will open up the container, so we can set a height value directly. But in IE7 and Firefox will not, it will not automatically open.

If you want to set the div adaptive height, we can adopt height:auto; This property, but this property IE6 is not supported. Does it have a headache? In fact, it is not difficult to solve this problem, but also a lot of methods, here is recommended a: (assuming we need to control the div minimum height is 100px, more than let the information inside automatically open):

HTML code

    1. . div{

    2. Height:auto!important;

    3. height:100px;

    4. min-height:100px;

    5. }

. div{height:auto!important; height:100px; min-height:100px;}

Note: Because!important in IE7 and Firefox can read, and the weight is higher than the back of the height:100px, so when the IE7 and Firefox display, will use the previous height:auto!important; And IE6 can not recognize!important,auto to it, so it will apply the style of the following height:100px, and min-height:100px that the div minimum height is 100px; This property is recognized in both IE7 and Firefox.

Such a perfect can set the div minimum height, but also can be div adaptive height CSS style is out, and compatible with IE6, IE7 and firefox!

div default height and adaptive height

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.