【问题标题】:Relative text centering. Vertically and horizontally [duplicate]相对文本居中。垂直和水平[重复]
【发布时间】:2012-02-16 05:06:27
【问题描述】:

可能重复:
Horizontally and vertically center a pre tag without the use of tables?

如何在不指定宽度的情况下将文本水平和垂直居中?

现在我有:

<div class="center">
<p id="logo"><span>Coming soon!</span></p>
</div>

CSS 是:

span {
    color:#ff0000;
    font-size: 14px;
    font-weight:normal;
    font-family:sans-serif;
    border-bottom-color: currentColor;
    border-bottom-style: dotted;
    border-bottom-width: 1px;
    line-height: 1.1;
}
.center {
    width:150px;
    height:100px;
    position:absolute;
    left:50%;
    top:50%;
    margin-left:-100px;
    margin-top:-50px;
}

因为文本的宽度不同,我需要另一种解决方案。

【问题讨论】:

    标签: html css


    【解决方案1】:

    为你的中心类提供以下 CSS:

    text-align:center;
    line-height: 100px;
    

    请注意,这仅适用于单行文本。请参阅 jsFiddle 上的示例。

    【讨论】:

      猜你喜欢
      • 2012-05-11
      • 2015-09-25
      • 2012-12-16
      • 2013-10-14
      • 2012-01-01
      • 2020-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多