Html:和标签的正确顺序是什么?

时间:2022-01-14 21:15:43

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:

我认为支持标签的唯一原因是:

<p>This is a longer sentence with a <a href=''>short link here</a></p>

这是一个较长的句子,此处有短链接

Thanks!

谢谢!

7 个解决方案

#1


40  

The first example is only allowed in HTML5.

第一个示例仅允许在HTML5中使用。

The second example is allowed in all versions of HTML/XHMTL.

所有版本的HTML / XHMTL都允许使用第二个示例。

#2


10  

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!

这是W3C标准。检查一下!

#3


4  

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开始,锚标签( )几乎可以包含任何内容,包括段落。所以任何一个例子都是有效的,尽管我倾向于在段落中使用锚点。

#4


2  

anchors (a) should be inside a block element. So

锚点(a)应位于块元素内。所以

<p><a>...</a></p>

#5


1  

I would say the second one, than the <p> is not inheriting attributes of <a> and keeping it's original formatting.

我会说第二个,而不是

继承的属性并保持它的原始格式。

#6


1  

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.

诸如之类的内联元素通常包含在块级元素中,例如

。块元素提供显示数据所需的结构。

#7


0  

I always put the <p> tags inside unless the amount of text is large.

除非文本量很大,否则我总是将

标记放在里面。

#1


40  

The first example is only allowed in HTML5.

第一个示例仅允许在HTML5中使用。

The second example is allowed in all versions of HTML/XHMTL.

所有版本的HTML / XHMTL都允许使用第二个示例。

#2


10  

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!

这是W3C标准。检查一下!

#3


4  

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开始,锚标签( )几乎可以包含任何内容,包括段落。所以任何一个例子都是有效的,尽管我倾向于在段落中使用锚点。

#4


2  

anchors (a) should be inside a block element. So

锚点(a)应位于块元素内。所以

<p><a>...</a></p>

#5


1  

I would say the second one, than the <p> is not inheriting attributes of <a> and keeping it's original formatting.

我会说第二个,而不是

继承的属性并保持它的原始格式。

#6


1  

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.

诸如之类的内联元素通常包含在块级元素中,例如

。块元素提供显示数据所需的结构。

#7


0  

I always put the <p> tags inside unless the amount of text is large.

除非文本量很大,否则我总是将

标记放在里面。