Html:<a> 和 <p> 标签的正确顺序是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6101711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Html: What is the correct order of <a> and <p> tags?
提问by j_syk
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.
我知道它们的功能相同,但这是一个最佳实践/标准问题。这也适用于 ul/ol。
The only reason I think to favor the <a>
tag inside is with a situation like:
我认为支持<a>
内部标签的唯一原因是以下情况:
<p>This is a longer sentence with a <a href=''>short link here</a></p>
<p>This is a longer sentence with a <a href=''>short link here</a></p>
Thanks!
谢谢!
回答by edeverett
The first example is only allowed in HTML5.
第一个示例只允许在 HTML5 中使用。
The second example is allowed in all versions of HTML/XHMTL.
在所有版本的 HTML/XHMTL 中都允许使用第二个示例。
回答by ChristianB
回答by Karl Nicoll
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.
从 HTML 5 开始,锚标记 ( <a></a>
) 几乎可以环绕任何内容,包括段落。所以任何一个例子都是有效的,尽管我更喜欢在段落内有锚点。
回答by George Kastrinis
anchors (a) should be inside a block element. So
锚点 (a) 应该在块元素内。所以
<p><a>...</a></p>
回答by mrkva
I would say the second one, than the <p>
is not inheriting attributes of <a>
and keeping it's original formatting.
我会说第二个,而<p>
不是继承属性<a>
并保持其原始格式。
回答by George Cummins
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.
内联元素<a>
通常包含在块级元素中,例如<p>
. 块元素提供了呈现数据所需的结构。
回答by Mertis
I always put the <p>
tags inside unless the amount of text is large.
我总是把<p>
标签放在里面,除非文本量很大。