一,派生选择器
li strong {
font-style: italic;
font-weight: normal;
}
指定一个元素中的子元素的样式。这种的选择器不会因为层级关系失效。如果li中包裹了其他包裹了strong的元素,那么strong元素的样式还是生效的。
h1 > strong {color:red;}
和派生选择器的功能差不多,不同的是,多层包裹的话不会生效。只有在h1中包裹的strong元素才能生效。
h1 + p {margin-top:50px;}
相邻兄弟选择器。拥有同一个父级元素的兄弟元素都能对该样式声明生效。
二,id选择器
#sidebar p {
font-style: italic;
text-align: right;
margin-top: 0.5em;
}
上面的时id选择器和派生选择器结果,得到的结果就是,id为sidebar的元素中的p元素样式为上述的样式。
三,类选择器
.fancy td {
color: #f60;
background: #666;
}
这个例子的意思为,td的父级元素的class等于fancy,那么这个父元素中包裹的td元素都会使用到上述的
td.fancy {
color: #f60;
background: #666;
}
基于td元素使用了fancy样式。
四,属性选择器
[title]{
color:red;
}
input[type="text"]
{
width:150px;
display:block;
margin-bottom:10px;
background-color:yellow;
font-family: Verdana, Arial;
}
input[type="button"]
{
width:120px;
margin-left:35px;
display:block;
font-family: Verdana, Arial;
}