HTML怎么添加滚动条

html-css011

HTML怎么添加滚动条,第1张

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<body>标签中,输入html代码:<div style="overflow: scroll">hello world!</div>。

3、浏览器运行index.html页面,此时成功在html中指定的div中添加了滚动条。

滚动条的设置有两种方式:

html 直接定义:先定义一个带有id的标签,这个标签是你想要访问的目标位置,然后在定义一个a标签(你点击后会跳转的链接)

如<table id="table"></table><a href="#table"></a>

js方式:

window.onload=function(){

      document.getElementById('haha').onclick=function(){

      var scrollHeight=document.body.scrollHeight/2

      scroll(0,Math.round(scrollHeight))

    }

 }