文本对齐:居中;不工作

text-align: center; not working

我已经在 J​​Sfiddle 中重新创建了它,但仍然无法正常工作。我错过了什么?

这是HTML

<div class="row">
<div class="6u 12u$(small)">    <span class="image fit"><img src="images/pic01.jpg" alt=""></span>

    <h2green class="h2green">HIDE IN PLAIN SIGHT</h2green>
    <p>Escape to the big city of your choice; top floor of the tallest skyscraper with a champagne bottle in the bucket filled with ice, this might be just what you need .</p>
</div>
<div class="6u$ 12u$(small)">   <span class="image fit"><img src="images/pic02.jpg" alt=""></span>

    <h2blue>ESCAPE TO THE COUNTRYSIDE</h2blue>
    <p>You deserve a relaxing break and a quality experience. We strive to make it that way by finding you the right property and making sure you receive the very best of service before and during your stay.</p>
</div>

这是CSS

h2green {
text-align: center;
font-family: Steelfish;
color: #80c342;
font-size: 3em;
}

h2blue {
text-align: center;
font-family: Steelfish;
color: #0080c6;
font-size: 3em;
}

所有文本总是左对齐,我需要它居中。

https://jsfiddle.net/m19f35nb/

我只想让所有的 H2 和 Ps 居中。

HTML中没有<h2green><h2blue>这样的东西。为了从错误中恢复,浏览器正在生成内联元素(text-align 属性 不适用)。

使用真正的 HTML (<h2 class="blue">) 然后改变 CSS 来匹配:h2.blue.

这里是 HTML 和 CSS 示例代码

 <h2 class="blue">ESCAPE TO THE COUNTRYSIDE</h2>
 <h2 class="green">ESCAPE TO THE COUNTRYSIDE</h2>

h2.green {text-align: center; font-family: Steelfish;color: #80c342;font-size: 3em;}

h2.blue { text-align: center; font-family: Steelfish; color: #0080c6; font-size: 3em; }