我在滚动div的中心问题

时间:2013-03-17 03:55:53

标签: html css

我正在尝试放置一个滚动的 div 。我希望它在页面上处于死角状态,但它没有使用我在下面提供的代码。请帮忙。

CSS

#content  
{
text-align: center;
}

.scroll
{
background-color:#fff;
color:#000;
width:500px;
height:400px;
overflow:scroll;
}

HTML

<div id ="content">
<div class="scroll"> Stuff </div>
</div>

4 个答案:

答案 0 :(得分:1)

div是块级元素,不会侦听text-algin。您需要在margin: 0 auto元素上使用.scroll或将div设为内联块元素。虽然不完全支持块级元素作为内联块级元素的支持,但您必须使用span来获得完整支持。但是,更好的选择是如果你的div有一个设定的宽度,在你想要居中的元素上使用auto的左右边距。

答案 1 :(得分:0)

text-align仅影响文字。要将<div>定位在中心,请使用
margin-left:auto;margin-right:auto

答案 2 :(得分:0)

您可以将display:inline;margin:auto添加到<div>

答案 3 :(得分:0)

试试这个

<强> HTML

<div id ="content">
<div class="scroll"> Stuff </div>
</div>

<强> CSS

#content  
{
    text-align: center;
    margin-left:auto;
    margin-right:auto;
    width:300px;
    height:200px;
    overflow: scroll;
}

.scroll
{
    background-color:#fff;
    color:#000;
    width:500px;
    height:400px;
}

live fiddle here

相关问题