div问题 在线等!!
我想固定一个div的高度 当里头的数据超过时用滚动条 可是现在当数据少时 div就会自己把高度降下来 怎么办呢?
[解决办法]
设定高
<DIV style="width:100;height:100; OVERFLOW-X: auto;OVERFLOW-Y: auto; scrollbar-face-color:#ffffff;scrollbar-shadow-color:#C1C1BB;scrollbar-highlight-color:#C1C1BB;scrollbar-3dlight-color:#EBEBE4;scrollbar-darkshadow-color:#EBEBE4;scrollbar-track-color:#F4F4F0;scrollbar-arrow-color:#000000; HEIGHT: 100px" >
[解决办法]
用Js来实现:
<!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=gb2312" /> <script type="text/javascript"> function $(o) { if(typeof(o)=="string") return document.getElementById(o); return o; } function autoContent(o,dHeight) { var obj=$(o); obj.style.overflow="auto"; if(parseInt(obj.scrollHeight)>=dHeight) { obj.style.height=dHeight+"px"; } else { obj.style.height="auto"; } } setInterval(function(){autoContent("atc",150);},10);</script></head> <body> <center> <input type="button" onclick="$('atc').innerHTML+='New Text<br/>'" value="Add Text"/> </center> <div style="width:200px;height:auto;border:1px solid red;margin:0px auto;padding-left:5px;" id="atc"> this is Content<br/> </div> </body> </html>
[解决办法]
也不用js那么麻烦啊,就是设定固定的高啊,再一句OVERFLOW-Y: auto就解决了啊
[解决办法]
接分接分`
[解决办法]
不设置高度属性,在DIV加几个回车也许可以达到你的效果