是否需要将、、、包裹起来?里面;标签,如果内容不是段落?
例如:
这没关系
<div>
<p>some <strong>long</strong> text</p>
<strong>- end -</strong>
<p>some long text</p>
</div>
或者这在语义上更正确?
<div>
<p>some <strong>long</strong> text</p>
<p><strong>- end -</strong></p>
<p>some long text</p>
</div>
For example:
This is ok
<div>
<p>some <strong>long</strong> text</p>
<strong>- end -</strong>
<p>some long text</p>
</div>
Or this is more semantically correct?
<div>
<p>some <strong>long</strong> text</p>
<p><strong>- end -</strong></p>
<p>some long text</p>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
学术答案:两者都是 XHTML 兼容的。
实际答案:浏览器不会对此表示关心
Academic answer: both are XHTML-compatible.
Practical answer: browsers won't give a sh@t about it
如果它不是段落,则不应将其标记为段落。 (HTML 规范解释了如何阅读 DTD确定文档中给定点允许使用哪些元素。)
…但是,我不知道这是什么。您应该遵循正常的语法规则。
If it isn't a paragraph, then it shouldn't be marked up as a paragraph. (The HTML specification explains how to read the DTD to determine what elements are allowed at a given point in a document.)
… however, I don't know what this is. You should follow the normal rules for grammar.
如果内容不是段落,则将其标记为段落是不符合语义的。
如果你的结束标记被设计为可供阅读,那么它是否实际上是一个段落是有争议的。如果它不是为阅读而设计的,那么它不应该使用面向阅读的标签(如
)进行标记,而应该位于 span 或 div 中,并应用样式表来使字体粗细。
If the content is not a paragraph, then it is not semantic to mark it as such.
If your end marker is designed to be read, then it is debatable whether or not it is actually a paragraph or not. If it's not designed to be read, then it shouldn't be marked up with reading-oriented tags like
<strong>
, but instead should be in a span or div with a stylesheet applied to make the font weight bold.规范没有并不是说你必须这样做。 验证器很高兴您将其放在其他块级容器中。
The spec doesn't say you have to. The validator is happy for you to have it in some other block-level container.
在我看来,“- end -”是
或p:after{content:"-end-"}
的情况Seems to me that "- end -" is a case for an
<hr/>
or ap:after{content:"-end-"}
正如您提到的,较低的在语义上更正确,因为
标记不是块级元素,这意味着您需要将其包装在
中。否则,我确信您在尝试验证 HTML 时会遇到问题。
As you mentioned the lower is more semantically correct as the
<strong>
tag is not a block level element which means you need to wrap it in the<p>
. Otherwise I'm sure you will come across issues when you try and validate your HTML.