避免常见的HTML5错误用法
来源:互联网 发布:华为实力到底如何知乎 编辑:程序博客网 时间:2024/05/21 10:20
不要使用section作为div的替代品
人们在标签使用中最常见到的错误之一就是随意将HTML5的<section>等价于<div>——具体地说,就是直接用作替代品(用于样式)。在XHTML或者HTML4中,我们常看到这样的代码:
<!-- HTML 4-style code -->
<div id="wrapper">
<div id="header">
<h1>My super duper page</h1>
Header content
</div>
<div id="main">
Page content
</div>
<div id="secondary">
Secondary content
</div>
<div id="footer">
Footer content
</div>
</div>
而现在在HTML5中,会是这样:
<!-- 请不要复制这些代码!这是错误的! -->
<section id="wrapper">
<header>
<h1>My super duper page</h1>
<!-- Header content -->
</header>
<section id="main">
<!-- Page content -->
</section>
<section id="secondary">
<!-- Secondary content -->
</section>
<footer>
<!-- Footer content -->
</footer>
</section>
这样使用并不正确:<section>并不是样式容器。section元素表示的是内容中用来帮助构建文档概要的语义部分。它应该包含一个头部。如果你想找一个用作页面容器的元素(就像HTML或者XHTML的风格),那么考虑如Kroc Camen所说,直接把样式写到body元素上吧。如果你仍然需要额外的样式容器,还是继续使用div吧。
基于上述思想,下面才是正确的使用HTML5和一些ARIA roles特性的例子(注意,根据你自己的设计,你也可能需要加入div)
<body>
<header>
<h1>My super duper page</h1>
<!-- Header content -->
</header>
<div role="main">
<!-- Page content -->
</div>
<aside role="complementary">
<!-- Secondary content -->
</aside>
<footer>
<!-- Footer content -->
</footer>
</body>
如果你还是无法确定使用哪种元素,那么我建议你参考HTML5 sectioning content element flowchart
人们在标签使用中最常见到的错误之一就是随意将HTML5的<section>等价于<div>——具体地说,就是直接用作替代品(用于样式)。在XHTML或者HTML4中,我们常看到这样的代码:
<!-- HTML 4-style code -->
<div id="wrapper">
<div id="header">
<h1>My super duper page</h1>
Header content
</div>
<div id="main">
Page content
</div>
<div id="secondary">
Secondary content
</div>
<div id="footer">
Footer content
</div>
</div>
而现在在HTML5中,会是这样:
<!-- 请不要复制这些代码!这是错误的! -->
<section id="wrapper">
<header>
<h1>My super duper page</h1>
<!-- Header content -->
</header>
<section id="main">
<!-- Page content -->
</section>
<section id="secondary">
<!-- Secondary content -->
</section>
<footer>
<!-- Footer content -->
</footer>
</section>
这样使用并不正确:<section>并不是样式容器。section元素表示的是内容中用来帮助构建文档概要的语义部分。它应该包含一个头部。如果你想找一个用作页面容器的元素(就像HTML或者XHTML的风格),那么考虑如Kroc Camen所说,直接把样式写到body元素上吧。如果你仍然需要额外的样式容器,还是继续使用div吧。
基于上述思想,下面才是正确的使用HTML5和一些ARIA roles特性的例子(注意,根据你自己的设计,你也可能需要加入div)
<body>
<header>
<h1>My super duper page</h1>
<!-- Header content -->
</header>
<div role="main">
<!-- Page content -->
</div>
<aside role="complementary">
<!-- Secondary content -->
</aside>
<footer>
<!-- Footer content -->
</footer>
</body>
如果你还是无法确定使用哪种元素,那么我建议你参考HTML5 sectioning content element flowchart
- 避免常见的HTML5错误用法
- 避免常见的6种HTML5错误用法
- 避免常见的6种HTML5错误用法
- 避免常见的6种HTML5错误用法
- 避免常见的6种HTML5错误用法
- 常见的六种html5错误用法(避免)
- 避免HTML5六种错误用法
- HTML5的6大常见错误用法,你…
- 前端:常见的6种HTML5错误用法
- 前端:常见的6种HTML5错误用法
- 常见的内存错误以及如何避免
- 常见的内存错误以及如何避免
- 避免APP常见错误
- 常见的4种HTML5错误用法,你用错了几个?
- SQL Server常见的需要避免的查询设计错误
- 避免常见的内存错误应注意的五点
- 程序员应该避免六个常见的开发错误
- 程序员应该避免六个常见的开发错误
- PopupWindow(四)
- 继承与接口之覆盖之一
- Java-调用抽象类中指定参数的构造方法
- hibernate防止sql注入(转载)
- jQuery (一)
- 避免常见的HTML5错误用法
- 直接拿来用!最火的Android开源项目(一)
- 如何将文件转成PDF
- ubuntu下使用tftp服务烧写TQ2440开发板
- ArrayList的使用方法
- C#4.0中的dynamic关键字和ExpandoObject对象
- Android 4.0 4.2 不能显示电池使用信息
- Eclipse中Outline里各种图标的含义
- 史玉柱:我是怎么做游戏策划的