我们可以在中使用任何其他标签吗?与- 一起?
我们可以在
一起使用任何其他 TAG 吗?
中与
喜欢
<ul>
Some text here or <p>Some text here<p> etc
<li>item 1</li>
Some text here or <p>Some text here<p> etc
<li>item 1</li>
</ul>
Can we use any other TAG in <ul>
along with <li>
?
like
<ul>
Some text here or <p>Some text here<p> etc
<li>item 1</li>
Some text here or <p>Some text here<p> etc
<li>item 1</li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
为了使您的代码有效,除了
之外,您不能将任何标记放入
中。
但是,您可以将任何块级元素放入
中,如下所示:
For your code to be valid you can't put any tag inside a
<ul>
other than an<li>
.You can however, put any block level element inside the
<li>
, like so:根据W3C推荐,一个列表必须是:
您只能将
p
标记放在li
标记内,而不是作为ul
的直接子级。 W3C 建议明确指出:According to the W3C Recommendation, the basic structure of a list must be:
You can put
p
tags only inside ofli
tags, not as direct children oful
. The W3C Recommendation expressly states:您可以使用模板标签,这是完全合法的。例如:
You can use template tag and it is totally legal. For example:
虽然您可以在其中包含其他标签(并且它可能工作得很好),但您不应该这样做,因为它不符合 w3c 标准。它也没有什么语义意义。
只需创建一个简单的页面并通过验证器运行它( http://validator.w3.org/ )并你会亲自看到:)
While you could have other tags inside (and it might work just fine), you shouldn't because it's not w3c-compliant. It also makes very little semantic sense.
Just create a simple page and run it throught the validator ( http://validator.w3.org/ ) and you'll see for yourself :)
不,这将是无效标记。但是,如果您尝试为某些行实现不同的外观和感觉,则可以通过向任何 li 标记添加特定的类名来实现。见下文:
No, this would be invalid markup. However, if you're trying to achieve a different look and feel for some of the lines, you can do this by adding a specific classname to any li tag instead. See below:
您可以编写此类标记,但您不应该,因为它不合规,并且您可能会在不同的浏览器中得到奇怪且意外的结果。
You can write such mark up but you shouldn't as it is non-compliant and you may get strange and unexpected results in different browsers.
除了 li 之外,我们不能在 ul 中放置任何标签。
但是,我们可以在 li 中放置其他标签,如下所示:
we can't put any tag inside ul other than li.
However, we can put other tags inside li, like this::
如果您这样做是为了设置列表元素的一部分的样式,您可以这样做
,然后使用 CSS
希望这会有所帮助
if your doing this to style a part of the list-element, you could do this
and then use the CSS
hope this helps
Knockout.js具体答案,可以使用下面的注释语法。
Knockout.js specific answer, you can use the following comment syntax.
HTML5 引用
https:// /html.spec.whatwg.org/multipage/grouping-content.html#the-ul-element 表示
ul
具有:“内容模型”是指我们可以在元素中放入的内容。
因此,由此我们了解到,只允许
li
像script
这样的东西。将其与
div
之类的元素进行比较,其中 https://html.spec.whatwg.org/multipage/grouping-content.html#the-div-element 说:那么“流内容”的定义就是一个包含大多数标签的巨大列表:
另请注意
text
是如何出现在其中的。然后我们看到它的定义 https://html.spec.whatwg.org /multipage/dom.html#text-content“元素间的空白定义为:
和“ASCII 空白”为 https://html.spec.whatwg。 org/multipage/dom.html#text-content
综上所述,除了前面提到的
li
和script
标签之外,我相信ul
中只允许使用上述空格。HTML5 验证器同意该理论: https://validator.w3.org/nu/#textarea< /a>
HTML5 quote
https://html.spec.whatwg.org/multipage/grouping-content.html#the-ul-element says that
ul
has:"Content model" means what we can put inside the element.
Therefore, from this we understand that only
li
things likescript
are allowed.Compare that to an element like
div
which https://html.spec.whatwg.org/multipage/grouping-content.html#the-div-element says:The definition of "flow content" is then a huge list that contains most tags:
Also note how
text
is present in there. We then see its definition https://html.spec.whatwg.org/multipage/dom.html#text-content"Inter-element whitespace is then defined as:
and "ASCII whitespace" as https://html.spec.whatwg.org/multipage/dom.html#text-content
From all of this, besides the previously mentioned
li
andscript
tags, I believe only the above whitespaces are allowed within aul
.The HTML5 validator agrees with that theory: https://validator.w3.org/nu/#textarea
不。如果是列表,则其中包含列表项。我看不出其中包含非列表项的列表有任何用处;这不是列表...
No. If it's list, it has list-items in it. I can't see any use for list with non-list-items in it; it's not list...