HTML怎么添加滚动条

html-css010

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页面中,我们有时需要让div中的内容超出后自动显示滚动条,我们可以这样设置:

代码如下:

<div

class="classlist">

<div

class="autoScroll">

<asp:RadioButtonList

ID="rblClasses"

runat="server"

DataTextField="className"

DataValueField="classID"

ForeColor="#FF4040">

</asp:RadioButtonList>

<asp:ImageButton

ID="imgSure"

runat="server"

ImageUrl="~/images/c_sure.jpg"

/>

<asp:ImageButton

ID="imgClose"

runat="server"

ImageUrl="~/images/c_close.jpg"

/>

</div>

</div>

然后,样式中这样设置:

代码如下:

<style

type="text/css">

.classlist

{

width:

300px

height:

20px

}

.autoScroll

{

width:300px

height:100px

overflow:auto

}

#rblClasses

{

margin-left:

20px

}

</style>

设置后,当radiobutton中显示的内容超出最外围的div时,将自动显示滚动条,即嵌套div

overflow:scroll /*任何时候都强制显示滚动条*/

overflow:auto /*需要的时候会出现滚动条*/

overflow-x:auto /*控制X方向的滚动条*/

overflow-y:auto /*控制Y方向的滚动条*/

受overflow影响的必需是块元素,并且指定宽度和高度,否则内部元素将自动将父级容器撑开。