在ul内嵌套其他html标签,但li除外 [英] nesting other html tags inside ul except li

查看:315
本文介绍了在ul内嵌套其他html标签,但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>

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

推荐答案

根据规范

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

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.

列表中的项目是ul元素的li元素子节点.

因此,UL元素的子元素必须li元素.

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

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

More specifically, it says under the ul tag:

内容模型:

   Zero or more li elements.

但这是完全合法的:

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

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

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