Div + CSS compatibility solves the problem of Div max width and Min width

Source: Internet
Author: User

During webpage creation, we often encounter min/max-width and min/max-height under IE6, which is one of the biggest headaches for web designers, the following methods can solve these problems and are relatively simple. Of course, if you still have a better method, I hope you can leave a message on the homepage:
<Div
Style = "Max-width: 250px;">In this text, ax/min is in IE7 +
And firfox, Safari, and operabrowsers are supported. The widest value is 250px. </div> However, IE6 cannot read this attribute. Fortunately, ie supports its own JavaScript attribute expression, For example:
Div {width: expression_r (250 + "PX ")}AndDiv {widt: 250px}In IE
The read operations are consistent! However, if some users disable javascript in the browser, this writing fails. Therefore, another method is required:
# 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 to width: 100%. In fact, this is a nonsense, because div is a block element, and the default width is the width of the parent element. In this example, the DIV width is equivalent to the body width if not declared.
We set the max-width of the container to 500px. This is effective for ff. It does not work for IE.
In the face of ineffective IE, we apply the expression_r embedded script to declare that when the width is greater than PX, the width is equal to PX.

Parseint (document. Body. currentstyle. fontsize )? "33em": "Auto" if the actual width is greater than (500/12) the size of the current font, set the page width to 33em.

Similarly, for the smallest width, it is the same as ax/min-hight:
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 ")
}
Minimum height:

# Mycss {

Min-Height: 333px;

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

There is also a simple method:

# A {Height: Auto
! Important; Min-Height: 400px ;}
This style can solve the minimum height problem in ie5.5, IE6, IE7, FF, Safari, and other browsers. The maximum height has never been practiced.

Share: QQ space Sina Weibo Renren kaixin.com more
Related Article

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.