CSS背景以及关系选择器,伪选择器

CSS的背景

1、backgound_color:transparent/color

2、backgound-image:添加背景图;none(无背景图,默认),url{url}

3、backgound-repeat:对象背景铺排方式;(repeat/no-repeat/repeat-x/repezt-y)

<style>
   body{
       background-color: #eee;
       background-image: url("OI.jpg");   //默认repteat
       background-repeat:repeat-y ;
  }
</style>

4、backgound-position:设置对象的背景图像位置;(x-number/top/center/bottom/y-number/left/right/)

5、backgound-attachment:背景图像的滚动位置:(scroll/fixed)

6、background:设置背景的复合写法。

backgound:color image repeat attachment postion

CSS伪类选择器

伪类:专门用来表示元素的一种特殊状态

常用的伪类选择器:

1、 a标签的伪类:link未访问状态 visited已被访问状态

hover:鼠标悬停状态 active:用户激活

2、focus:获得焦点

<style>  
input:focus{
    outline: 1px solid hotpink;
}
</style>

3、first-child/last-child:nth-child(number)

  <style>
 ul li:first-child{
     color: red;
}
</style>

属性选择器:

[属性名]:包含有指定属性名的元素

<style>
.hao[title]{
   font-weight: bold;
}
</style>
?
?
<div class="hao" title="内容">dix</div>

[属性名=值]:属性名的值为指定的元素

<style>
input[name=hi]{
       background: blueviolet;
  }
</style>

[属性名~=值]:属性名的值为指定的元素

[属性名^=值]:属性名的值并以指定值的开头的元素

[属性名$=值]:属性名的值并以指定值的结尾的元素

关系选择器

1、空格 :后代选择器;

h1 strong{                 //样式对所以的子类都有用
   color: slateblue;

2、>:只选择儿子元素;

 h1>strong{                 //只有第二层的儿子元素才能用样式
   color: slateblue;
}

3、+:兄弟选择器

ul li+li{
   color: brown;
   list-style-type: none;
}
?
<ul>
  <li>li2</li>
  <li>li2</li>
  <li>li2</li>
  <li>li2</li>
  <li>li2</li>
  <li>li2</li>
</ul>

CSS背景以及关系选择器,伪选择器

从第二个使用该样式;

CSS伪元素:

1、CSS伪元素与伪类的区别:伪类用于已经存在的元素处于某个状态时,添加相应的样式,根据用户的行为变化而变化;

而伪元素是用于创建一些不在文档树中的元素,并为其添加样式;,用户虽然可以看到这些文本,但是文本不在文档树中;

2、特点:都不会出现在源文档或者文档树中;

大小写不敏感;

伪类可以出现在任何地方,伪元素只能在只能跟在选择器中;

有些伪类是互斥的,而它可以同时用在一个元素上

3、 :before/:after/:first-letter/:first-line:前面可以是一个冒号,也可以是双冒号;

::select/::placeholder/::backdrop,前面必须是双冒号

 

CSS背景以及关系选择器,伪选择器

 

 

CSS背景以及关系选择器,伪选择器

上一篇:js判断素数


下一篇:IIS报错-An error occurred on the server when processing the URL. Please contact the system administrator. If you are the system administrator please click here to find out more about this error.