御品VPS

御品VPS---独特的心情尽在御品VPS

HTML5 语义元素

<div> <div> <h1>HTML5 <span>语义元素</span> </h1>


<p>语义= 意义</p> <p>语义元素 = 有意义的元素</p>
<h2>什么是语义元素?</h2> <p>一个语义元素能够清楚的描述其意义给浏览器和开发者。</p> <p>无语义 元素实例: <div> 和 <span> - 无需考虑内容.</p> <p>语义元素实例: <form>, <table>, and <img> - 清楚的定义了它的内容.</p>
<h2>浏览器支持</h2> <p>HTML5 语义元素HTML5 语义元素HTML5 语义元素HTML5 语义元素HTML5 语义元素</p> <p>Internet Explorer 9+, Firefox, Chrome, Safari 和 Opera 支持语义元素。</p> <p>注意: Internet Explorer 8 及更早版本不支持该元素。 但是文章底部提供了兼容的解决方法.</p>
<h2>HTML5中新的语义元素</h2> <p>许多现有网站都包含以下HTML代码: <div id="nav">, <div class="header">, 或者 <div id="footer">, 来指明导航链接, 头部, 以及尾部.</p> <div style="width:374px;float:left"> <p>HTML5 提供了新的语义元素来明确一个Web页面的不同部分:</p> <ul> <li><header></li> <li><nav></li> <li><section></li> <li><article></li> <li><aside></li> <li><figcaption></li> <li><figure></li> <li><footer></li> </ul> </div> <div style="width:260px;float:left;margin-bottom:15px">HTML5 语义元素</div>
<h2>HTML5 <section> 元素</h2> <p><section> 标签定义文档中的节(section、区段)。比如章节、页眉、页脚或文档中的其他部分。</p> <p>根据W3C HTML5文档: section 包含了一组内容及其标题。</p> <div> <h2>实例</h2> <div> <div><span><</span><span>section</span><span>></span><span> </span><span><</span><span>h1</span><span>></span><span>WWF</span><span></</span><span>h1</span><span>></span><span> </span><span><</span><span>p</span><span>></span><span>The World Wide Fund for Nature (WWF) is....</span><span></</span><span>p</span><span>></span><span> </span><span></</span><span>section</span><span>></span></div> </div>
</div>

<h2>HTML5 <article> 元素</h2> <p> <article> 标签定义独立的内容。.</p> <p><article> 元素使用实例:</p> <ul> <li>Forum post</li> <li>Blog post</li> <li>News story</li> <li>Comment</li> </ul> <div> <h2>实例</h2> <div> <div><span><</span><span>article</span><span>></span><span> </span><span><</span><span>h1</span><span>></span><span>Internet Explorer 9</span><span></</span><span>h1</span><span>></span><span> </span><span><</span><span>p</span><span>></span><span>Windows Internet Explorer 9(缩写为 IE9 )在2011年3月14日21:00 发布。</span><span></</span><span>p</span><span>></span><span> </span><span></</span><span>article</span><span>></span></div> </div>
</div>

<h2>HTML5 <nav> 元素</h2> <p><nav> 标签定义导航链接的部分。</p> <p><nav> 元素用于定义页面的导航链接部分区域,但是,不是所有的链接都需要包含在 <nav> 元素中! </p> <div> <h2>实例</h2> <div> <div><span><</span><span>nav</span><span>></span><span> </span><span><</span><span>a</span><span> </span><span>href</span><span>=</span><span>"</span><span>/html/</span><span>"</span><span>></span><span>HTML</span><span></</span><span>a</span><span>></span><span> | </span><span><</span><span>a</span><span> </span><span>href</span><span>=</span><span>"</span><span>/css/</span><span>"</span><span>></span><span>CSS</span><span></</span><span>a</span><span>></span><span> | </span><span><</span><span>a</span><span> </span><span>href</span><span>=</span><span>"</span><span>/js/</span><span>"</span><span>></span><span>JavaScript</span><span></</span><span>a</span><span>></span><span> | </span><span><</span><span>a</span><span> </span><span>href</span><span>=</span><span>"</span><span>/jquery/</span><span>"</span><span>></span><span>jQuery</span><span></</span><span>a</span><span>></span><span> </span><span></</span><span>nav</span><span>></span></div> </div>
</div>

<h2>HTML5 <aside> 元素</h2> <p><aside> 标签定义页面主区域内容之外的内容(比如侧边栏)。</p> <p>aside 标签的内容应与主区域的内容相关.</p> <div> <h2>实例</h2> <div> <div><span><</span><span>p</span><span>></span><span>My family and I visited The Epcot center this summer.</span><span></</span><span>p</span><span>></span><span> </span><span><</span><span>aside</span><span>></span><span> </span><span><</span><span>h4</span><span>></span><span>Epcot Center</span><span></</span><span>h4</span><span>></span><span> </span><span><</span><span>p</span><span>></span><span>The Epcot Center is a theme park in Disney World, Florida.</span><span></</span><span>p</span><span>></span><span> </span><span></</span><span>aside</span><span>></span></div> </div>
</div>

<h2>HTML5 <header> 元素</h2> <p><header>元素描述了文档的头部区域</p> <p> <header>元素主要用于定义内容的介绍展示区域.</p> <p>在页面中你可以使用多个<header> 元素.</p> <p>以下实例定义了文章的头部:</p> <div> <h2>实例</h2> <div> <div><span><</span><span>article</span><span>></span><span> </span><span><</span><span>header</span><span>></span><span> </span><span><</span><span>h1</span><span>></span><span>Internet Explorer 9</span><span></</span><span>h1</span><span>></span><span> </span><span><</span><span>p</span><span>></span><span><</span><span>time</span><span> </span><span>pubdate</span><span> </span><span>datetime</span><span>=</span><span>"</span><span>2011-03-15</span><span>"</span><span>></span><span></</span><span>time</span><span>></span><span></</span><span>p</span><span>></span><span> </span><span></</span><span>header</span><span>></span><span> </span><span><</span><span>p</span><span>></span><span>Windows Internet Explorer 9(缩写为 IE9 )是在2011年3月14日21:00发布的</span><span></</span><span>p</span><span>></span><span> </span><span></</span><span>article</span><span>></span></div> </div>
</div>

<h2>HTML5 <footer> 元素</h2> <p><footer> 元素描述了文档的底部区域.</p> <p> <footer> 元素应该包含它的包含元素</p> <p>一个页脚通常包含文档的作者,著作权信息,链接的使用条款,联系信息等</p> <p>文档中你可以使用多个 <footer>元素.</p> <div> <h2>实例</h2> <div> <div><span><</span><span>footer</span><span>></span><span> </span><span><</span><span>p</span><span>></span><span>Posted by: Hege Refsnes</span><span></</span><span>p</span><span>></span><span> </span><span><</span><span>p</span><span>></span><span><</span><span>time</span><span> </span><span>pubdate</span><span> </span><span>datetime</span><span>=</span><span>"</span><span>2012-03-01</span><span>"</span><span>></span><span></</span><span>time</span><span>></span><span></</span><span>p</span><span>></span><span> </span><span></</span><span>footer</span><span>></span></div> </div>
</div>

<h2>HTML5 <figure> 和 <figcaption> 元素</h2> <p><figure>标签规定独立的流内容(图像、图表、照片、代码等等)。</p> <p><figure> 元素的内容应该与主内容相关,但如果被删除,则不应对文档流产生影响。</p> <p><figcaption> 标签定义 <figure> 元素的标题.</p> <p><figcaption>元素应该被置于 "figure" 元素的第一个或最后一个子元素的位置。</p> <div> <h2>实例</h2> <div> <div><span><</span><span>figure</span><span>></span><span> </span><span><</span><span>img</span><span> </span><span>src</span><span>=</span><span>"</span><span>img_pulpit.jpg</span><span>"</span><span> </span><span>alt</span><span>=</span><span>"</span><span>The Pulpit Rock</span><span>"</span><span> </span><span>width</span><span>=</span><span>"</span><span>304</span><span>"</span><span> </span><span>height</span><span>=</span><span>"</span><span>228</span><span>"</span><span>></span><span> </span><span><</span><span>figcaption</span><span>></span><span>Fig1. - The Pulpit Pock, Norway.</span><span></</span><span>figcaption</span><span>></span><span> </span><span></</span><span>figure</span><span>></span></div> </div>
</div>

<h2>我们可以开始使用这些语义元素吗?</h2> <p>以上的元素都是块元素(除了<figcaption>).</p> <p>为了让这些块及元素在所有版本的浏览器中生效,你需要在样式表文件中设置一下属性 (以下样式代码可以让旧版本浏览器支持本章介绍的块级元素):</p> <div><div> header, section, footer, aside, nav, article, figure
{
    display: block;
} </div></div> <h2> Internet Explorer 8 及更早IE版本中的问题</h2> <p>IE8 及更早IE版本无法在这些元素中渲染CSS效果,以至于你不能使用 <header>, <section>, <footer>, <aside>, <nav>, <article>, <figure>, 或者其他的HTML5 elements.</p> <p>解决办法: 你可以使用HTML5 Shiv Javascript脚本来解决IE的兼容问题。HTML5 Shiv下载地址:</p> <p>下载后,将以下代码放入到网页中:</p> <div> <div> <!--[if lt IE 9]>
<script src="html5shiv.js"></script>
<![endif]--> </div></div> <p>以上代码在浏览器小于IE9版本时会加载html5shiv.js文件. 你必须将其放置于<head> 元素中,因为 IE浏览器需要在头部加载后渲染这些HTML5的新元素</p> </div> </div>

未经允许不得转载:御品VPS » HTML5 语义元素

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址