什么是语义化标签?
在HTML 5出来之前,我们用div来表示页面章节,但是这些div都没有实际意义。(即使我们用css样式的id和class形容这块内容的意义)。这些标签只是我们提供给浏览器的指令,只是定义一个网页的某些部分。但现在,那些之前没“意义”的标签因为因为html5的出现消失了,这就是我们平时说的“语义”。
它的常用标签有哪一些?
1.section元素 表示页面中的一个区块。
2.article元素 表示一块与上下文无关的独立的内容。
3.aside元素 在article之外的,与article内容相关的辅助信息。
4.header元素 表示页面中一个内容区块或整个页面的标题。
5.footer元素 表示页面中一个内容区块或整个页面的脚注。
6.nav元素 表示页面中导航链接部分。
7.figure元素 表示一段独立的内容,使用figcaption元素为其添加标题(第一 个或最后一个子元素的位置)。
8.main元素 表示页面中的主要的内容(ie不兼容)。
9.hgroup标题的一个分组。
10.mark定义高亮显示的文本(span)。
11.time时间。
12.dialog标记定义一个对话框(会话框)类似微信。
13.embed 标记定义外部的可交互的内容或插件 比如flash。
通过了解了它的一些属性及含义,也许感觉还是有点懵,或者说思路不是太清晰,下面我们通过一个简单的案例来展示它的结构框架,俗话说得好一通百通!
下面我们来试试下图中的这个结构框架:
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin:0;
padding:0;
}
h1,h2,h3,h4,h5,h6{
font-size: 16px;
font-weight: normal;
}
ul,ol,li{
list-style: none;
}
.box{
width:900px;
height:542px;
margin:0 auto;
border:3px solid red;
margin-top: 50px;
}
header{
height:82px;
background:#f47d31;
font-size: 50px;
font-weight: bold;
line-height: 82px;
text-transform: capitalize;
color:#fff;
text-align: center;
}
section{
height:408px;
background:#888888;
}
nav{
width:230px;
height:408px;
background: #888888;
padding-left: 5px;
float:left;
}
nav h1{
font-size: 14px;
font-weight: bold;
color: white;
line-height: 12px;
text-align: center;
margin: 18px 0;
}
nav li{
width:215px;
height:42px;
border-bottom: 3px white solid;
font-size: 12px;
font-weight: bold;
line-height: 42px;
color: #f47d31;
float:left;
}
main{
width:410px;
height:408px;
background:pink;
padding: 0 10px;
float:left;
}
aside{
width:200px;
height:408px;
background: #888888;
padding: 0 15px;
float: right;
}
aside h1{
font-size: 14px;
font-weight: bold;
color: white;
line-height: 12px;
text-align: center;
margin: 18px 0;
}
aside p{
font-size: 12px;
line-height: 21px;
color: white;
text-indent: 2em;
}
article{
height: 194px;
background:#ccc;
margin-top: 10px;
}
article header{
height:26px;
color: #fff;
font-size: 14px;
line-height: 26px;
}
article p{
font-size: 10px;
line-height: 20px;
color: black;
margin: 15px 0 15px 0;
text-indent:2em;
}
article footer{
height:26px;
background: #f47d31;
height:26px;
font-size: 10px;
line-height: 26px;
color: #fff;
}
footer{
height:52px;
background:#f47d31;
text-align: center;
font-size:10px;
line-height: 52px;
color:#fff;
text-transform: capitalize;
}
</style>
</head>
<body>
<div class="box">
<header>header</header>
<section>
<nav>
<h1>Nav</h1>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
<li>Link4</li>
</nav>
<main>
<article>
<header>article header</header>
<p>文本文本文本文本文本文本文本文文本文本文本文本文本文文本文本文本文本文本文文本文本文本文本文本文文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本。</p>
<footer>article footer</footer>
</article>
<article>
<header>article header</header>
<p>文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本。</p>
<footer>article footer</footer>
</article>
</main>
<aside>
<h1>Aside</h1>
<p>文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本本文本文本文本文本文本文本文本文本文本文本文本文本。</p>
</aside>
</section>
<footer>footer</footer>
</div>
</body>
</html>
当然以上的代码并不是特别的完善,还有许多需要改进及优化的地方,作为萌新的一员,我会加倍努力,我相信时间能证明一切!让我们一起进步,一起加油!