给你一段JS,是国外一个老外写的,可以支持IE6 max-width,max-height,min-width.min-height属性,这个方法不一定会比楼上几位说的在CSS里面加expression()好,但是这个方法调用比较简单,直接在头部<head></head>之间加这样一句话就行,<script type="text/javascript" src="minmax.js"></script>。我下面有一个样例,由于没有服务器,JS不能直接调用,你把代码复制下来,把附件里的minmax.rar下载下来,解压出来跟你复制下来的代码放在一起运行一下就知道效果了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>minmax.js example page</title> <style type="text/css"> body{ font-family:Arial, Helvetica, sans-serif; font-size:13px; } .wrap{ margin:0 auto; width:90%; border:1px solid #F30; padding:10px; max-height:60px; overflow:auto; } </style> <script type="text/javascript" src="minmax.js"></script> </head> <body> <div class="wrap"> This element normally takes up 90% of the window width, but it will always be at least 16em wide, and never wider than 32em. Also, it will always be at least 150px high, possibly higher if there is more text. Furthermore, lorem ipsum dolor sit amet thingy thing lorem lorem lorem flippin' lorem where's my textfile full of greeking when I need it? Lorem lorem lorem lorem rhubarb rhubarb and a lorem.<br /> This element normally takes up 90% of the window width, but it will always be at least 16em wide, and never wider than 32em. Also, it will always be at least 150px high, possibly higher if there is more text. Furthermore, lorem ipsum dolor sit amet thingy thing lorem lorem lorem flippin' lorem where's my textfile full of greeking when I need it? Lorem lorem lorem lorem rhubarb rhubarb and a lorem. http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_tonThis element normally takes up 90% of the window width, but it will always be at least 16em wide, and never wider than 32em. Also, it will always be at least 150px high, possibly higher if there is more text. Furthermore, lorem ipsum dolor sit amet thingy thing lorem lorem lorem flippin' lorem where's my textfile full of greeking when I need it? Lorem lorem lorem lorem rhubarb rhubarb and a lorem.<br /> This element normally takes up 90% of the window width, but it will always be at least 16em wide, and never wider than 32em. Also, it will always be at least 150px high, possibly higher if there is more text. Furthermore, lorem ipsum dolor sit amet thingy thing lorem lorem lorem flippin' lorem where's my textfile full of greeking when I need it? Lorem lorem lorem lorem rhubarb rhubarb and a lorem. http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_tonThis element normally takes up 90% of the window width, but it will always be at least 16em wide, and never wider than 32em. Also, it will always be at least 150px high, possibly higher if there is more text. Furthermore, lorem ipsum dolor sit amet thingy thing lorem lorem lorem flippin' lorem where's my textfile full of greeking when I need it? Lorem lorem lorem lorem rhubarb rhubarb and a lorem.<br /> This element normally takes up 90% of the window width, but it will always be at least 16em wide, and never wider than 32em. Also, it will always be at least 150px high, possibly higher if there is more text. Furthermore, lorem ipsum dolor sit amet thingy thing lorem lorem lorem flippin' lorem where's my textfile full of greeking when I need it? Lorem lorem lorem lorem rhubarb rhubarb and a lorem. http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_tonThis element normally takes up 90% of the window width, but it will always be at least 16em wide, and never wider than 32em. Also, it will always be at least 150px high, possibly higher if there is more text. Furthermore, lorem ipsum dolor sit amet thingy thing lorem lorem lorem flippin' lorem where's my textfile full of greeking when I need it? Lorem lorem lorem lorem rhubarb rhubarb and a lorem.<br /> This element normally takes up 90% of the window width, but it will always be at least 16em wide, and never wider than 32em. Also, it will always be at least 150px high, possibly higher if there is more text. Furthermore, lorem ipsum dolor sit amet thingy thing lorem lorem lorem flippin' lorem where's my textfile full of greeking when I need it? Lorem lorem lorem lorem rhubarb rhubarb and a lorem. http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_ton http://hi.baidu.com/wely_ton </div> </body> </html>
提示:您可以先修改部分代码再运行
附件

minmax.rar (1.68 KB)
2009-10-28 15:21, 下载次数: 57
作者: piaopoliulang
发布时间: 2009-10-28