中心文本水平和垂直元素

时间:2015-02-04 05:15:49

标签: html css css3 twitter-bootstrap

我试图在我的#modal元素中垂直和水平居中一些文字:

#modal
{
background: gray;
    color: white;
    white-space: nowrap;
    width: 427px;
    height: 999px;
}

http://jsfiddle.net/4js3runn/



<div id="modal">
    <span>CENTRE THIS</span>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

查看jsfiddle代码: http://jsfiddle.net/4js3runn/1/

#modal {
    background: none repeat scroll 0 0 gray;
    color: white;
    float: left;
    height: 100vh;

    position: relative;
    width: 100%;
}
.center {
    background-color: #444;
    height: 30px;
    left: 50%;
    line-height: 30px;
    margin-left: -56px;
    margin-top: -15px;
    position: absolute;
    text-align: center;
    top: 50%;
    width: 112px;
}
<div id="modal">
    <div class="center">CENTRE THIS</div>
</div>
相关问题