HTML文本对齐属性不起作用

时间:2014-08-04 16:05:59

标签: html css text-align

我遇到了" text-align"属性因为在以下代码中不起作用:

<Titulo1>Title Text</Titulo1>
<BR>
<h1>Normal Text</h1>

CSS:

*               {font-family: Arial; color: #2D2D2D}
Titulo1         {font-size: 40px; font-weight: 900; text-align: center}
TextoNormal     {font-size: 30px; text-align: center}

以下是更多详细信息:http://jsfiddle.net/jB7X3/3/

1 个答案:

答案 0 :(得分:4)

自定义标记默认为inline元素。您需要向其添加display: block

<强> Demo

CSS

* {
    font-family: Arial;
    color: #2D2D2D
}
Titulo1 {
    font-size: 40px;
    font-weight: 900;
    text-align: center;
    display: block /* add this if you wish to continue using your css */
}
TextoNormal { /* css property are not applied by content, so this will not work */
    font-size: 30px;
    text-align: center;
}

/* or a better way as in html */

<!-- or better way -->


<div>Title Text</div>

div{
    text-align: center;
}

h1 {
text-align: center;
}