Problems with automatic support of Div height (compatible with IE and ff)

Source: Internet
Author: User

Transferred from:

Http://hi.baidu.com/%B9%F9%E8%B40110/blog/item/130a6d253bdcba0b4c088def.html

Http://www.xnwai.com /? Tag = ie % E4 % B8 % 8eff % E4 % B8 % addiv % E8 % 87% Aa % E5 % 8A % A8 % E6 % 92% E5 % A4 % A7 % E7 % 9A % 84% E9 % 97% AE % E9 % A2 % 98

 

 

This problem occurs again on the typographical page today. You can write the following code before: Height: Auto! Important; Height: 200px; Min-Height: 200px; remember to remove Height: 200px; otherwise IE6 will hide the excess content. I tried it. Yes, (* ^__ ^ ...... Continue to work!

Min-height is a very convenient CSS command, which can specify that the element is at least or less than a certain width, so as to ensure correct layout. However, ie does not recognize this, but it actually uses width as the smallest width. IE6 sets the height and width. When the content exceeds the limit, the DIV will automatically increase. Min-width is useful for IE7 and ff. The best way is to write: Height: Auto! Important; Height: 200px; Min-Height: 200px; overflow: hidden; in this way, both IE6, IE7, and FF work, that is, when the content does not exceed 200px, The DIV will display the height of 200px. When the content exceeds 200px, it will automatically increase.

Else ---------------------------------------------------------------------------------------------------------------------------------

Example:

<style type = "style/CSS"> <br/>. head {width: 980px; Height: 100px; Background-color: #66ff33 ;}< br/>. content {width: 980px; Background-color: # FFFF00 ;}< br/>. left {float: Left; width: 200px; Height: 300px; margin-left: 50px; Background-color: #99 FFFF ;}< br/>. right {float: Left; width: 200px; Height: 300px; margin-left: 50px; Background-color: # ff33ff ;}</P> <p>. foot {width: 980px; Height: 100px; Background-color: #330000 ;} </P> <p> </style> <br/> <Div class = "head"> <br/> </div> <br/> <Div class =" content "> <br/> <Div class =" Left "> <br/> </div> <br/> <Div class =" right "> <br/> </div> </P> <p> </div> <br/> <Div class = "footer"> <br/> </div>

someone on csdn asked this question.
the problem is: The following Code can achieve the desired effect in IE, And the content (DIV) is automatically extended, however, content (DIV) under FF will not be extended.
In Fact, I encountered this problem at the beginning of my website.
the parent element cannot adapt to the height of the child element in a non-IE browser.
the first thing we need to know here is. A parent element without a float definition does not automatically calculate the height in the default state.
you must add a secondary element and define clear: Both.
In this method. The content was successfully added, but footer was invisible.
final solution.

<Style type = "style/CSS"> <br/>. head {width: 980px; Height: 100px; Background-color: #66ff33 ;}< br/>. content {width: 980px; Background-color: # FFFF00; overflow = auto ;}< br/>. left {float: Left; width: 200px; Height: 300px; margin-left: 50px; Background-color: #99 FFFF ;}< br/>. right {float: Left; width: 200px; Height: 300px; margin-left: 50px; Background-color: # ff33ff ;}</P> <p>. foot {width: 980px; Height: 100px; Background-color: #330000 ;}< br/>. clear {clear: Both ;} <br/> </style> <br/> <Div class = "head"> <br/> </div> <br/> <Div class = "content"> <br/> <Div class = "Left"> <br/> </div> <br/> <Div class = "right"> <br/> </div> <br/> <Div class = "clear"> <br/> </div> </P> <p> </div> <br/> <Div class =" footer "> <br/> </div>

You only need to add the Attribute Overflow: auto in the content main container;/* force the parent element to adapt to the height of the child element */
As for clear, only the floating elements on both sides are clear.

Solve the problem :)

 

Note: div # Clear plays an important role in it.

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.