中可以包含哪些元素?标签?

发布于 2024-09-12 15:49:39 字数 61 浏览 1 评论 0原文

标记中可以包含哪些有效的 html 元素(如果有)?

What are the valid html elements, if any, that can be contained within a <a> tag?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

万人眼中万个我 2024-09-19 15:49:39

内联元素(a、span、strong、em 等)可以包含其他内联元素和文本节点。锚点可以包含跨度,跨度可以包含文本节点。

一般来说,块级元素可以
包含内联元素和其他
块级元素。一般来说,
内联元素可能只包含数据
和其他内联元素。固有于
这种结构上的区别是
块元素创建的想法
比内联“更大”的结构
元素。

来自http://www.w3.org/TR/html401/struct/global。 html

正如其他答案中所述,您不能将 a 嵌套在 a 中。

Inline elements ( a, span, strong, em among others ) can contain other inline elements and text nodes. An anchor can contain a span, which can contain a text node.

Generally, block-level elements may
contain inline elements and other
block-level elements. Generally,
inline elements may contain only data
and other inline elements. Inherent in
this structural distinction is the
idea that block elements create
"larger" structures than inline
elements.

From http://www.w3.org/TR/html401/struct/global.html

As noted in other answers, you can't nest an a in an a.

著墨染雨君画夕 2024-09-19 15:49:39

An <a> tag can contain any Inline Element besides another <a> tag.

眉目亦如画i 2024-09-19 15:49:39

请参阅规范的锚点部分

<!ELEMENT A - - (%inline;)* -(A)       -- anchor -->

相关部分是 (%inline;)* -(A),这意味着“%inline 组中除 A 元素之外的任何内容”。 %inline 带有超链接,方便您展开它。

See the anchor section of the specification.

<!ELEMENT A - - (%inline;)* -(A)       -- anchor -->

The relevant section is (%inline;)* -(A), which means "Anything in the group %inline excluding A elements". %inline is hyperlinked to make it easier for you to expand it.

岁月打碎记忆 2024-09-19 15:49:39

它可以包含纯文本和内联元素。内联元素如下:

TT | I | B | BIG | SMALL | EM | STRONG | DFN | CODE | SAMP | 
KBD | VAR | CITE | ABBR | ACRONYM | A | IMG | OBJECT | BR | 
SCRIPT | MAP | Q | SUB | SUP | SPAN | BDO

但是 A 不能嵌套在另一个 A 中,并且嵌套 SCRIPT 没有意义。

It can contain plain text and inline elements. Inline elements are following:

TT | I | B | BIG | SMALL | EM | STRONG | DFN | CODE | SAMP | 
KBD | VAR | CITE | ABBR | ACRONYM | A | IMG | OBJECT | BR | 
SCRIPT | MAP | Q | SUB | SUP | SPAN | BDO

But A can not be nested in another A and nesting SCRIPT doesn't make senese.

苹果你个爱泡泡 2024-09-19 15:49:39

锚标记是内联元素,因此它可以包含其他内联元素(其他锚标记除外)。

如果要将块元素放入锚点内,则必须使用内联元素,并使用 CSS 将其与锚点标签本身一起转换为块元素。

示例:

<a href="page.html" class="blocklink"><span>eat me</span></a>

CSS:

.blocklink { display: block; }
.blocklink span { display: block; }

An anchor tag is an inline element, so it can contain other inline elements (except other anchor tags).

If you want to put a block element inside an anchor, you have to use an inline element and turn it into a block element using CSS, along with the anchor tag itself.

Example:

<a href="page.html" class="blocklink"><span>eat me</span></a>

CSS:

.blocklink { display: block; }
.blocklink span { display: block; }
回眸一笑 2024-09-19 15:49:39

下面的示例完成了来自 https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element:concept-element-content-model

a 元素可以包裹整个段落列表
表格,等等,甚至整个部分,只要没有
其中的交互式内容(例如按钮或其他链接)。

<aside>
 <h1>Advertising</h1>
 <a href="https://www.example.com">
  <section>
   <h1>Fun Travel!</h1>
   <p>Travel to Neverland</p>
   <p>$9.99 + free transfer.</p>
  </section>
 </a>
 <a href="https://www.example.com">
  <section>
   <h1>Family Fun!</h1>
   <p>Visit us at Freeland</p>
   <p>No charge!</p>
  </section>
 </a>
</aside>

The below example completes @aya answer from https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element:concept-element-content-model:

The a element can be wrapped around entire paragraphs, lists,
tables, and so forth, even entire sections, so long as there is no
interactive content within (e.g., buttons or other links).

<aside>
 <h1>Advertising</h1>
 <a href="https://www.example.com">
  <section>
   <h1>Fun Travel!</h1>
   <p>Travel to Neverland</p>
   <p>$9.99 + free transfer.</p>
  </section>
 </a>
 <a href="https://www.example.com">
  <section>
   <h1>Family Fun!</h1>
   <p>Visit us at Freeland</p>
   <p>No charge!</p>
  </section>
 </a>
</aside>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文