最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
IE6下最大宽度最小宽度最大高度和最小高度
时间:2016-03-15 编辑:简简单单 来源:一聚教程网
CSS2.0中有四个属性是设置元素最大宽度、最小宽度、最大高度和最小高度的,它们分别是:max-width、min-width、max-height和min-height。使用它们,可以方便为元素设定最大、最小宽度和高度。
但是,万恶的IE6竟然不支持它。所以我们只能对IE6另外寻找方法了,本文使用的方法是expression。代码如下:
最小??度
.min_width{min-
/* sets max-width for IE */
_width:expression(document.body.clientWidth < 300 ? "300px" : "auto");
}
最大??度
.max_width{
max-
/* sets max-width for IE */
_width:expression(document.body.clientWidth > 600 ? "600px" : "auto");
}
最小高度
.min_height{
min-
/* sets min-height for IE */
_height:expression(this.scrollHeight < 200 ? "200px" : "auto");
}
最大高度
.max_height{
max-
/* sets max-height for IE */
_height:expression(this.scrollHeight > 400 ? "400px" : "auto");
}
最大最小??度
.min_and_max_width{
min-
max-
/* 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-
max-
/* sets min-height & max-height for IE */
_height: expression(
this.scrollHeight < 200 ? "200px" :
( this.scrollHeight > 400 ? "400px" : "auto")
);
}
解释一下代码中的expression:expression是微软为IE5.0版本以后的浏览器加入到一个属性,用来把CSS属性和JavaScript 表达式关联起来。简单的说就是CSS属性后面可以跟一段JavaScript表达式。上面的例子就是通过JavaScript表达式计算出元素的最大、最 小宽度和高度的值,然后赋予CSS。
相关文章
- Java计算球从100米高度自由落下问题 04-24
- 高度预警曝光 五星财富涉嫌诈骗勾当 10-08
- 坚守“非遗”传承阵地,提升实践研究高度 07-03
- button在firefox 和chrome高度不一致问题解决办法 04-19
- IE6,IE7 DIV固定高度的技巧 07-19
- 最小高度100%页脚保持在底部的方法 04-25