Html:的正确顺序是什么?和标签?
以下哪一项(如果有的话)按照标准是正确的?
<!-- Do the links surround the target link object -->
<a href=''><p>Link Description</p></a>
<!-- or does the object type encapsulate the link-->
<p><a href=''>Link Description</a></p>
我知道它们的功能相同,但这是一个最佳实践/标准问题。这也适用于 ul/ol。
我认为倾向于使用 标签的唯一原因是在以下情况下:
这是一个带有 的较长句子。短链接在这里
谢谢!
Which of the following, if either, is correct by standards?
<!-- Do the links surround the target link object -->
<a href=''><p>Link Description</p></a>
<!-- or does the object type encapsulate the link-->
<p><a href=''>Link Description</a></p>
I know they function the same, But it's a best practice/standards question. This could apply to ul/ol too.
The only reason I think to favor the <a>
tag inside is with a situation like:
<p>This is a longer sentence with a <a href=''>short link here</a></p>
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
第一个示例仅在 HTML5 中允许。
第二个示例在所有版本的 HTML/XHMTL 中都允许。
The first example is only allowed in HTML5.
The second example is allowed in all versions of HTML/XHMTL.
不能用内联元素包裹块元素。您必须按照以下方式执行此操作:
链接说明
这是 W3C 标准。检查这个!
You can't wrap a block element with an inline element. You have to do this in that way:
<p><a href=''>Link Description</a></p>
This is W3C standard. Check this!
从 HTML 5 开始,锚标记 (
) 几乎可以环绕任何内容,包括段落。所以这两个例子都是有效的,尽管我更喜欢在段落内放置锚点。
As of HTML 5, anchor tags (
<a></a>
) are allowed to wrap around almost anything, including paragraphs. So either example is valid, although I tend to prefer having anchors inside paragraphs.锚点 (a) 应该位于块元素内。所以
anchors (a) should be inside a block element. So
我想说第二个,
没有继承
的属性并保持其原始格式。
I would say the second one, than the
<p>
is not inheriting attributes of<a>
and keeping it's original formatting.内联元素(例如
)通常包含在块级元素(例如
)内。块元素提供了呈现数据所需的结构。
Inline elements such as
<a>
are often contained within block-level elements such as<p>
. The block elements provide the structure needed to present your data.除非文本量很大,否则我总是将
标签放在里面。
I always put the
<p>
tags inside unless the amount of text is large.对于现在正在查看此问题的任何人,这里有一个链接,为已接受的答案添加了更多上下文。
HTML5 规范
For anyone looking at this now, here is a link that adds more context to the accepted answer.
HTML5 specification