给DIV添加滚动条
工作就是这样,你可以选择在安逸空间里晒太阳;也可以选择通过自我提升来品味另一空间的气候...
转自:http://yangfei520.blog.51cto.com/1041581/381508
直接为div指定overflow属性为auto即可,但是必须指定div的高度,如下:
<div style="position:absolute; height:400px; overflow:auto"> </div>
如果要出现水平滚动条,则: overflow-x:auto 同理,垂直滚动条为: overflow-y:auto 如果该div被包含在其他对象例如td中,则位置可设为相对:position:relative
例如:
<html> <head> <title>测试表格内的滚动条</title> </head> <body> <table> <tr> <td>表格内的滚动条:</td> <td> <div id="wins" style="position:absolute;height:200;width:200;overflow:auto;background:#EEEEEE;"> <p>pppppppppppppppppppppppppppppppppppppppppppppppppp </p> <p>pppppppppppppppppppppppppppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> <p>ppppppppppppppppppppppppp </p> </div> </td> </tr> <tr> <td colspan="2" align="right"> <span onmouseover='scrollb=setInterval("wins.scrollLeft-=10",100)' onmouseout=clearInterval(scrollb)>向左</span> <span onmouseover='scrollb=setInterval("wins.scrollTop-=10",100)' onmouseout=clearInterval(scrollb)>向上</span> <span onmouseover='scrollb=setInterval("wins.scrollLeft+=10",100)' onmouseout=clearInterval(scrollb)>向右</span> <span onmouseover='scrollb=setInterval("wins.scrollTop+=10",100)' onmouseout=clearInterval(scrollb)>向下</span> </td> </tr> </table> </body> </html>