CSS文本不会浮动在中心对齐div下面

时间:2015-03-24 05:52:32

标签: html css

我希望我的“body2”div位于页面中央,并且段落向左浮动。但我的代码在两次潜水时都应用了中心对齐属性。 我在CSS中使用了float for para但没有解决方案。

<div class="row body2" align="center">

        <div class="writing">
            <div class="date">13.01.15</div><br>
            <div class="heading">My biggest audio project ever.</div>

            <div class="container-fluid">
            <div class="para">The complete setup took about 6 hours. We were extremely contended with the result taken into the account of everything is new. A late 
            </div><br><br>

            </div>
            </div>
    </div>

CSS:我正在使用text-align:left来使我的段落保持对齐,但它显示中心对齐。

.body2
{
    background-color: black;
    margin-top: -10px;
    margin-left: auto;
    margin-right: auto;
}
.writing
{
    margin-top:64px ;
    margin-left: 88px;
    padding-bottom: 50px;
}
.date
{
    color: #716558;
    font-family: myrid Pro;
    font-size: 20px;
}
.heading
{
    font-family: georgia;
    font-size: 36px;
}
.para
{
    margin-top: 40px;
    line-height: 170%;
    text-align:left;
}

4 个答案:

答案 0 :(得分:0)

在这种情况下,align属性充当text-align。相反,您可以为.body2提供非自动宽度,并应用margin: auto;以使换行居中:JS Fiddle

.body2 {width: 70%; margin: auto;}//can also apply max-width

答案 1 :(得分:0)

如果你想将div对齐到页面中间,

.body2{ width: 500px; margin: 0 auto;}

这会将您的div对齐到页面的中心,根据您的要求更改宽度。

将文字对齐

.para{text-align:left;}

用户这一行,应该运转好运

答案 2 :(得分:0)

您可以通过设置div margin auto .body2{margin:0 auto;text-align:left}并删除align =&#34; center&#34;来自<div class="row body2" align="center">,导致你的文字居中,或设置div body2位置绝对.body2{position:absolute; width: 300px; left: 50%; margin-left:-150px}该样式会将你的div放在页面的中心,希望对你有帮助

答案 3 :(得分:-1)

            完整的设置大约需要6个小时。我们极为争辩的结果是一切都是新的。迟到了