CSS3-属性选择器

1.各种不同内科浏览器的css3适配

-webkit-transition: 1s;        /*Chrom、Safari*/

-moz-transition: 1s;            /*Firefox*/

-ms-transition: 1s;            /*IE*/

-o-transition: 1s;            /*Opera*/

transition: 1s;                /*标准*/

2.CSS3属性选择器

 
  2.1书写格式  标签名字[选择器名字]{修改的内容}         
           与CSS2的区别       
               1.多了自定义选择器名字   (css2中只有id 和 class)
               2.不仅可以选择选择器还可以选择选择器=“name” 更加精准  (css2中只能 #name 和 .name) 
  1. div[id="box"]{
  2. background:red;
  3. height:100px;
  4. 100px;
  5. }
  6. li[color]{
  7. background:green;
  8. }
  9. li[color="red"]{
  10. background:yellow;
  11. }
  12. li[app]{
  13. background:pink;
  14. }
  15. <divid="box"class="box"></div>
  16. <ul>
  17. <licolor='red'>red</li>
  18. <licolor='green'>green</li>
  19. <licolor='blue'>blue</li>
  20. <liapp='yellow'>yellow</li>
  21. <licolor='pink'>pink</li>
  22. </ul>
    2.2书写格式  E:nth-child(n)  

                 E标签名                n第几个(从1开始的)

                从E标签的父级中去找(正着找)第n个标签,并且这个标签必需是E

               还有一相反的 E:nth-last-child(n)  ,    这个是从父级中倒着找。

 
  1. p:nth-child(1){
  2. background: red;
  3. }
  4. p:nth-child(2){
  5. background: green;/*这里就不会显示绿色·因为第二个不是p标签*/
  6. }
  7. span:nth-child(2){
  8. background: blue;
  9. }
  10. <div>
  11. <p>red</p>
  12. <span>green</span>
  13. <p>blue</p>
  14. <span>yellow</span>
  15. <p>pink</p>
  16. </div>
 
2.3书写格式   E:nth-child(odd)   /    E:nth-child(even)
            odd   奇数行
            even  偶数行
  1. li:nth-child(odd){
  2. background: red;
  3. }
  4. li:nth-child(even){
  5. background: green;
  6. }
  7. <ul>
  8. <li>red</li>
  9. <li>green</li>
  10. <li>blue</li>
  11. <li>yellow</li>
  12. <li>pink</li>
  13. </ul>

2.4书写格式   E:nth-of-type(n)  

            E标签名            n第几个(从1开始的)

           从E标签的父级中去找(正着找)第n个E标签

          E:nth-last-of-type(n)

     从E标签的父级中倒着去找

  1. p:nth-of-type(1){
  2. background: red;
  3. }
  4. p:nth-of-type(2){
  5. background: green;
  6. }
  7. span:nth-of-type(3){
  8. background: blue;
  9. }
  10. <div>
  11. <p>red</p>
  12. <span>green</span>
  13. <p>blue</p>
  14. <span>yellow</span>
  15. <p>pink</p>
  16. <span>green</span>
  17. <span>green</span>
  18. <span>green</span>
  19. </div>

2.5 E:not(s)   排除掉某一个元素  

      E                      标签

      s                      要排除掉的那个标签的class或者id

  1. p:not(.green){
  2. background: red;
  3. }
  4. <div>
  5. <p>red</p>
  6. <pclass="green">green</p>
  7. <p>blue</p>
  8. </div>
 
2.6E~F            找到E标签后面的所有F标签  
  1. ul~p{
  2. background: red;
  3. }
  4. ul~span{
  5. background: green;
  6. }
  7. <div>
  8. <ul>
  9. <li><span>red</span></li>
  10. <li><p>pink</p></li>
  11. </ul>
  12. <p>green</p>
  13. <span>blue</span>
  14. <p>black</p>
  15. <span>yellow</span>
  16. </div>
  17. <div>
  18. <span>green</span>
  19. </div>
 
 

 

 

 

 
原文地址:https://www.cnblogs.com/CafeMing/p/6279368.html