CSS选择器

2016-05-24  本文已影响59人  柯良勇

CSS常见选择器的类别

选择器的优先级

class 和 id 的使用场景

使用CSS选择器时命名空间的划定

CSS选择器示例

#header{}
.header{}
.header .logo{}
.header.mobile{}
.header p, .header h3{}
#header .nav>li{}
#header a:hover{}

常见伪类选择器

:hover 鼠标悬停时的样式;
:active鼠标按下保持的样式;
:focus在输入框选中时的样式;
E:first child 选择E元素,且该E元素是第一子元素;
E:first-of-type 选择E元素,且该E元素是同类标签的第一个。

:first-child和:first-of-type的区别

选择器及样式示例

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>first-child  vs first-of-child</title>
  <style>

    .item1:first-of-type{
      background: red;
    }
    
    .item1:first-child{
      color: blue;
    }

  </style>
</head>
<body>
 <div class="item1">111</div>
 <div class="ct">
   <p class="item1">222</p>
   <div class="item1">333</div>
   <div class="item1">444</div>
   <div class="item2">
     <div class="item1">555</div>
     <div class="item1">666</div>
   </div>
 </div>
</body>
</html>

text-align: center的作用解析

属性兼容性的查询

上一篇下一篇

猜你喜欢

热点阅读