DIV+CSS compatible with div max width and minimum width issues

Source: Internet
Author: User

In the production of web pages, we often encounter min/max-width,min/max-height under IE6 is not valid, this is one of the Web designer's most headache problem, the following methods can solve these problems, and relatively simple. Of course, if you have a better way, wish to leave a message to me on the homepage:
<div style= "max-width:250px;" > This text content, ax/min in IE7 + and Firfox,safari,opera browser support, the widest value is 250px</div>But IE6 can't read this property, but IE it supports its own JavaScript attribute expression, for example:
Div{width:expression_r(250+ "px")} and div{widt:250px} in IE's recognition is consistent! However, if some users disable JavaScript in the browser, this will fail. So, a different approach is needed:
#mycss {
width:100%;
max-width:500px;
Width:expression_r (Document.body.clientWidth > 500?) "500px": "Auto"); }

Or:
#mycss {
Max-width:33em;
Width:expression_r (Document.body.clientWidth > (500/12) * parseint (document.body.currentStyle.fontSize)? "33em": "Auto");
}

We set the width of the container mycss: width:100%; In fact, this is a nonsense, because the div is a block element, the default width is the width of the parent element. In this case, the div width, if not declared, is equal to the body width.
We set the max-width of the container to 500px. This is valid for FF. For IE, it has no effect.
In the face of no effect of IE, we apply expression_r embedded script, declared that when the width is greater than 500px, the width is equal to 500px.

parseint (document.body.currentStyle.fontSize)? " 33em ":" Auto "If this actual width is greater than (500/12) the size of the current font, the width of the set page is 33em.

Similarly, for the smallest width, and ax/min-hight, it is the same:
Minimum:
#mycss {
min-width:333px;
Width:expression_r (Document.body.clientWidth < 334?) "333px": "Auto");
}

Maximum height:

#mycss {
max-height:333px;

Height:expression_r (This.scrollheight > 332?) "333px": "Auto")
}
Min. Height:

#mycss {

min-height:333px;

Height:expression_r (This.scrollheight < 334?) "333px": "Auto");
}

There is also an easy way to do this:

#a {Height:auto!important; min-height:400px;}
This style can be in ie5.5,ie6,ie7 and Ff,safari and other browsers to solve the minimum height problem, the maximum height has not been practiced, hehe.

This article transferred from: http://www.cnblogs.com/hnyei/archive/2011/09/19/2181367.html

DIV+CSS compatible with div max width and minimum width issues

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.