将ul标签嵌入ul以外的其他标签 [英] nesting html tags inside ul other than li

查看:238
本文介绍了将ul标签嵌入ul以外的其他标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些代码片断在语法上是正确的吗?我正在使用第一个代码段来构建一个导航(在ul中嵌套标题标签)。如果它是错误的或者这是一个坏习惯有什么缺点。

 < ul class =site-title left> 
< header>
< li>< h1>网站标题< / h1>< / li>
< / header>
< / ul>

 < ul class =site-title left> 
< span>
< li>< h1> site-title< / h1>< / li>
< / span>
< / ul>


解决方案



根据规格 a>, ul元素为:


ul元素表示项目列表,其中项目的顺序并不重要 - 也就是说,更改顺序不会实质性地更改文档的含义。 / p>

列表的项是ul元素的li元素子节点。


所以UL元素的子元素必须是 li 元素。



更具体地说,它在 ul 标记下显示:


内容模型:

 零个或多个li元素。 


然而,这样做完全合法:

 < ul class =site-title left> 
< li>< span>< h1> site-title< / h1>< / span>< / li>
< / ul>


Are these code pieces syntactically correct? I am using first code piece to build a navigation (nesting header tag inside ul). If it is wrong or it is a bad practice what are the drawbacks.

<ul class="site-title left">
  <header>
   <li><h1>site title</h1></li>
  </header>                         
</ul>

and

<ul class="site-title left">
  <span>
   <li><h1>site-title</h1></li>
  </span>                           
</ul>

解决方案

No

According to the spec, the ul element is:

The ul element represents a list of items, where the order of the items is not important — that is, where changing the order would not materially change the meaning of the document.

The items of the list are the li element child nodes of the ul element.

So the children of the UL element must be li elements.

More specifically, it says under the ul tag:

Content model:

   Zero or more li elements.

It is however, perfectly legal to do:

<ul class="site-title left">
   <li><span><h1>site-title</h1></span></li>
</ul>

这篇关于将ul标签嵌入ul以外的其他标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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