在网页制作中经常要控制div宽度最大宽度/高度或者最小宽度/高度,但是在IE6中很多朋友都会遇到不兼容的头疼问题,包括我也经常遇到这样的问题,在百度查了很多都没法解决,后来在一个论坛上学习到,在这里跟大家分享下,经过时间完全兼容各大主流浏览器。

/* 最小寬度 */
.min_width{min-width:300px;
 /* sets max-width for IE */
 _width:expression(document.body.clientWidth < 300 ? "300px" : "auto");
}

/* 最大寬度 */
.max_width{
 max-width:600px;
 /* sets max-width for IE */
 _width:expression(document.body.clientWidth > 600 ? "600px" : "auto");
}

/* 最小高度 */
.min_height{
 min-height:200px;
 /* sets min-height for IE */
 _height:expression(this.scrollHeight < 200 ? "200px" : "auto");
}

/* 最大高度 */
.max_height{
 max-height:400px;
 /* sets max-height for IE */
 _height:expression(this.scrollHeight > 400 ? "400px" : "auto");
}

/* 最大最小寬度 */
.min_and_max_width{
 min-width:300px;
 max-width:600px;
 /* sets min-width & max-width for IE */
 _width: expression(
 document.body.clientWidth < 300 ? "300px" :
 ( document.body.clientWidth > 600 ? "600px" : "auto")
 );
}

/* 最大最小高度 */
.min_and_max_height{
 min-height:200px;
 max-height:400px;
 /* sets min-height & max-height for IE */
 _height: expression(
 this.scrollHeight < 200 ? "200px" :
 ( this.scrollHeight > 400 ? "400px" : "auto")
 );
}