css背景图片

一、伪类选择器——选择子代选择器

1.表示选中ul下的第二个li,字体为红色

例:ul li:nth-child(2){

                    color:red;

                   }

 

2.选择偶数项

例:ul li:nth-child(even){

                    color:red;

                   }

 

3.选择奇数项

例:ul li:nth-child(odd){

                    color:red;

                   }

 

4.父级元素下只存在一个子级的时候

(1)例:. box em:only-child{

                    color:red;

                   }

(2)例:. box em:only-of-type{

                    color:red;

                   }

 

5.选中父级元素中第一个p

例:. box em:first-child{

                    color:red;

                   }

 

6.选中父级元素中最后一个p

例:. box em:last-child{

                    color:red;

                   }

 

7.选中box元素中倒数第二个p元素

例:. box em:nth-last-child(2){

                    color:red;

                   }

 

 

二、伪元素选择器

(1):before

例:表示在em元素之前添加“China”

 em:before{

                    content:China;

                   }

 

(2):after

例:表示在em元素之后添加“China”

 em:after{

                    content:China;

                   }

 

(3)设置第一个字或字母的样式

例:. box3 p:first-letter{

                    color:red;

                   }

 

(4)设置第一行的样式

例:. box3 p:first-line{

                    color:red;

                   }

 

 

三、同级选择器

兄弟元素1“+”兄弟元素2

例:表示选择h1后的同级p元素——h1+p

 

 

四、设置图片平铺方式:

1.background-repeat:no-repeat;——不平铺

2.background-repeat:repeat-x;——平铺x轴

3.background-repeat:repeat-y;——平铺y轴

 

 

五、设置背景位置,取值top(顶部)、bottom(底部)、top right(右上)、bottom right(右下)

例:background-position:bottom;

例:background-position:bottom right;

 

 

六、background简写

background:color url repeat position——background:颜色 路径 是否平铺 位置(定位)

例:background:url (“../imges/dm_pic03.jpg”)no-repeat top-left;

 

 

七、设置边框四个角的弧度:

border-radius:20px;   同时设置四个角的弧度为20px

border-radius:20px 50px;   20px设置左上和右下、50px设置右上和左下

border-radius:20px 50px 10px;    20px设置左上、50px设置右上和左下、10px设置右下

border-radius:10px 20px 30px 40px;      设置左上、右上、右下、左下

 

 

八、列表声明

1. list-style:none;     去掉无序列表前的圆点

2. list-style:square;     把无序列表前的圆点改成实心方块

3. list-style:circle;     把无序列表前的圆点改成空心圆

posted on 2017-10-21 20:54  张萤莹  阅读(983)  评论(0编辑  收藏  举报