html怎么居中div里的内容

html-css011

html怎么居中div里的内容,第1张

内容是标签还是文字,文字的话直接给div设置text-align: center

标签的话居中需要知道宽度,然后设置margin: 0 auto行内元素不能设置宽度需要加个display:inline-block转成行内块。

在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