为什么这个XHTML无效? HTML:
<h2>earthquake warning <span>Posted 03/11/2009 at 2.05pm</span></h2>
CSS:
h2 {
font: bold 20px Arial, "Helvetica Neue", Helvetica, Geneva, sans-serif;
padding-bottom: 5px;
padding-top: 5px;
text-transform: uppercase;
}
h2 span {
font-weight: normal;
text-transform: none;
display: inline;
}
答案 0 :(得分:7)
更多的是将h2
放入span
。
完整来源:
<span class="warning">
<h2>Bushfire warning <span>Posted 03/11/2009 at 2.05pm</span></h2>
<p class="warning" />Dignissim elit quod dolore sollemnes iriure. Ut suscipit nunc laoreet lectorum facilisi. Consequat eodem consequn congue humanitatis. Vel in litterarum odio solissi. <a href="#">For more information click here.</a>
</span>
您不能将h2放在span标记内。请尝试使用div
代替:
<div class="warning">
<h2>Bushfire warning <span>Posted 03/11/2009 at 2.05pm</span></h2>
<p class="warning" />Dignissim elit quod dolore sollemnes iriure. Ut suscipit nunc laoreet lectorum facilisi. Consequat eodem consequn congue humanitatis. Vel in litterarum odio solissi. <a href="#">For more information click here.</a>
</div>
答案 1 :(得分:3)
因为h2在一个范围内。您不能将块元素(h2)放在内联元素(span)中。
用div替换范围。
答案 2 :(得分:-2)
它实际上是有效的,你只需要设置字体大小和系列
我编辑了
div.content h2 span {
display:block;
font-size:12px;
font-weight:normal;
text-transform:none;
}
结果如下:sample