如果你像这样编写“正常”方式,我发现最终结果是一样的:
<p>
This is a paragraph text section.
</p>
<p>
This is a paragraph text section.
</p>
<p>
This is a paragraph text section.
</p>
<p>
This is a paragraph text section.
</p>
与这样的编码相比,其中每个其他段落文本都用p:
编码This is a paragraph text section.
<p>
This is a paragraph text section.
</p>
This is a paragraph text section.
<p>
This is a paragraph text section.
</p>
这样可以节省空间,但有没有令人信服的理由不这样做?
答案 0 :(得分:4)
正如@StuartLC所指出的那样:
适用于p的css不会应用于跳过的段落
虽然您的代码存在此行为风险,但您仍然可以通过考虑HTML5中的结束p
代码为optional来缩小代码。 Google的风格指南甚至推荐omitting optional tags。
所以你可以编写这样的代码,而不会丢失任何p
CSS属性:
<p>This is a paragraph text section.
<p>This is a paragraph text section.
<p>This is a paragraph text section.
<p>This is a paragraph text section.
<强>段强>
body {font: 13px verdana;}
p {color: red;}
<strong>Alternating `p` elements:</strong>
<p>This is a paragraph text section.</p>
This is a paragraph text section.
<p>This is a paragraph text section.</p>
This is a paragraph text section.
<hr>
<strong>With no closing `p` tags:</strong>
<p>This is a paragraph text section.
<p>This is a paragraph text section.
<p>This is a paragraph text section.
<p>This is a paragraph text section.