CSS选择器

几种选择器:3种,标签名选择器,clsss选择器,id选择器。

对于同样的CSS属性,选择器优先级是,id选择器>class选择器>标签名选择器。class+标签名选择器>class选择器。

对于不同的CSS属性,继承。上面优先级反走。


请看例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSS的基本选择器</title>
</head>
<style type="text/css">
h1
{color:blue; font-size:25px; text-decoration:underline;}
em
{ color:red;}

.red
{ color:red; font-size:18px;}

#one
{ font-weight:bold; font-size:36px;}
.two
{ font-weight:lighter; font-size:13px;}

p span
{ color:#00FF00;}
p
{font-weight:normal; font-size:55px;}

.father div
{ background-color:red;
}
.son
{
background-color
:blue;

}
</style>

<body>
<h1>标签名选择器</h1>
<class="red">class选择器</p>
<class="red">还是class选择器</p>
<id="one">id选择器</p>
<p><span>嵌套选择器</span></p>
<h1><em>嵌套选择有继承特性</em></h1>
<id="one" style=" font-weight:lighter; font-size:13px">行内样式>ID选择器</p>
<id="one" class="two">ID选择器>class选择器</p>
<class="two">class选择器>标签名选择器</p>

<div class="father">背景色为red
<div class="son">class+标签名选择器>class选择器</div>
</div>

</body>
</html>

posted @ 2011-04-16 15:22  草珊瑚  阅读(1127)  评论(1编辑  收藏  举报