日期:2014-05-17 浏览次数:20834 次
[id^=s]{
background:#0C6;
}
[id*=s]{
background:#0C6;
}
/*a标签的href超链接的地址的末尾是"/"或者是"htm"或者是"html",使用此样式*/
a[href$=\/]:after,a[href$=html]:after{
content:"想睡";
}
/*a标签的href超链接的地址的末尾是jpg,使用此样式*/
a[href$=jpg]:after{
content:"困了";
}
/*对第一行设置样式*/
p:first-line{
color:#000;
}
/*对第一个字或字母或日文使用样式*/
p:first-letter{
color:#000;
font-size:24px;
}
/*p标签之前插入文字*/
p:before{
content:"插入文字 ";
}
/*p标签之后插入文字*/
p:after{
content:"插入文字 ";
}
/*root结构选择器。指定整个网页的背景颜色 如果你设置body的背景色后,那么body的背景色,只会显示有数据的地方*/
:root{
background:#ccc;
}
/*not结构选择器。排除body和* 下面的h1不使用此样式*/
body *:not(h1){
background-color:#0CF;
}
/*empty结构选择器。当元素内容为空白时,使用样式.可以使用在表格中,用来设置摸个单元格为空时的样式*/
:empty{
background:#C33;
}
/*target结构选择器,对页面中某个target元素(该元素的id呗当做页面中的超链接使用)指定样式。该样式,只在用户点击了页面的超链接,并且调准到target页面时起作用*/
:target{
background:#993;
}
/*单独指定第一个子元素*/
li:first-child{
background:#fff;
}
/*单独指定最后一个子元素*/
li:last-child{
background:#fff;
}
/*对指定序号的子元素使用样式,根据你传入的值不同,他还可以对所有的第奇数个子元素或第偶数个子元素使用样式*/
li:nth-child(3){
background:#000;
color:#fff;
}
/*对指定序号的子元素使用样式,根据你传入的值不同,他还可以对所有的第奇数个子元素或第偶数个子元素使用样式 基数odd,偶数even*/
li:nth-last-child(2){
background:#03F;
color:#fff;
}
/*
使用它们替换nth-child和nth-last-child
避免出现问题。
这两个选择器在计算时,只针对同类型的子元素进行计算
*/
h2:nth-of-type(odd){
background:yellow;
}
h2:nth-of-type(even){
background:skyblue;
}/*
这里是吧nth-child中的n替换成xn+y;x=每几个一组;y=第几组;共12个li
*/
li:nth-child(4n+1){
background:blue;
}
li:nth-child(4n+2){
background:#ccc;
}
li:nth-child(4n+3){
background:#0CC;
} li:only-child{
background:yellow;
}
/*html代码:*/
<ul>
<li>唯一列表项目</li>
</ul>
<ul>
<li>列表项目1</li>
<li>列表项目2</li>
<li>列表项目3</li>
<li>列表项目4</li>
</ul>