将李先生包装在一个包装中是否合法? [英] Is it legal to wrap li in a?

查看:132
本文介绍了将李先生包装在一个包装中是否合法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我努力了解这里的文档: http:// w3c。 github.io/html-reference/terminology.html#transparent ,它从这里链接到: http://w3c.github.io/html-reference/a.html#a-changes



至于我知道下面的代码应该可以:

 <!doctype html> 
< head>< title> Yo!< / title>
< body>
< ul>
< a>
< li>我的列表项目被包裹在锚点中。
< / a>
< / ul>

但是当我将这段代码粘贴到不同的验证器中时,他们都同意li元素不能被包装在这样的一个元素中。我是否阅读了错误的文档,或者是我发现过时的所有验证器? 解决方案

首先,您没有使用HTML规范。 http://w3c.github.io/html-reference/ 只是一个非规范性引用,并且过时(这是2012年的草稿)。 HTML5规范(目前是最新的HTML W3C推荐标准) https://www.w3.org/TR/2014/REC-html5- 20141028 / HTML 5.1 目前是候选推荐标准(它很可能是W3C推荐标准)。 em>以下链接指向HTML5 W3C推荐标准。






a 元素透明。内容模型解释了 a 元素可能包含的其他元素。对于透明的情况,这意味着将使用父元素的内容模型。但内容模型并没有说明 a 元素可能出现在哪里.¹



这个元素的上下文可以用²列出元素可能出现的地方。在 a 的情况下,它是:


其中短语内容是预期的。


所以你可以在任何你可以使用文本的地方使用 a abbr span 等等。请注意, li code> li 不是短语内容)。 ul 元素< a>:它只允许 li 和脚本支持元素(而不是 a )。






1除 a 嵌套在 a 元素,当然。但是这是明确不允许的:必须没有互动内容后裔。



²此列表是非规范性的(仅为方便起见)。您可以通过检查每个可能的父级内容模型来查看规范上下文。


I struggle a bit to understand the documentation here: http://w3c.github.io/html-reference/terminology.html#transparent which is linked to from here: http://w3c.github.io/html-reference/a.html#a-changes

As far as I understand it the following code should be ok:

<!doctype html>
<head><title>Yo!</title>
<body>
    <ul>
        <a>
            <li>My list item is wrapped in an anchor.
        </a>
    </ul>

But when I paste this code in different validators, they all agree that the li element can not be wrapped in an a element like this. Am I reading the documentation wrong, or is all the validators I found outdated?

解决方案

First of all, you are not using a HTML specification. http://w3c.github.io/html-reference/ is just a "non-normative reference", and outdated (it’s a draft from 2012).

The HTML5 specification (which is currently the latest HTML W3C Recommendation) is https://www.w3.org/TR/2014/REC-html5-20141028/. HTML 5.1 is currently a Candidate Recommendation (it will likely be a W3C Recommendation soon).

The following links point to the HTML5 W3C Recommendation.


The content model of the a element is transparent. The content model explains what other elements the a element may contain. In the case of transparent, it means that the parent element’s content model will be used. But the content model says nothing about where the a element may appear.¹

The "contexts in which this element can be used"² lists where the element may appear. In the case of a, it’s:

Where phrasing content is expected.

So you can use a wherever you would also be allowed to use text, abbr, span etc. Note that the li element is not listed here (li is not phrasing content).

See the content model of the ul element: it only allows li and "script-supporting" elements (not a).


¹ Except for a elements nested in an a element, of course. But this is explicitly not allowed: "there must be no interactive content descendant".

² This listing is non-normative (only provided for convenience). You can see the normative contexts by checking each possible parent’s content model.

这篇关于将李先生包装在一个包装中是否合法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆