05-偽類選擇器


偽類選擇器一般會用在超鏈接a標簽中,使用a標簽的偽類選擇器,我們一定要遵循"愛恨准則"  LoVe HAte

 1               /*沒有被訪問的a標簽的樣式*/
 2         .box ul li.item1 a:link{
 3             
 4             color: #666;
 5         }
 6         /*訪問過后的a標簽的樣式*/
 7         .box ul li.item2 a:visited{
 8             
 9             color: yellow;
10         }
11         /*鼠標懸停時a標簽的樣式*/
12         .box ul li.item3 a:hover{
13             
14             color: green;
15         }
16         /*鼠標摁住的時候a標簽的樣式*/
17         .box ul li.item4 a:active{
18             
19             color: yellowgreen;
20         }
View Code

 

再給大家介紹一種css3的選擇器nth-child()

              /*選中第一個元素*/
        div ul li:first-child{
            font-size: 20px;
            color: red;
        }
        /*選中最后一個元素*/
        div ul li:last-child{
            font-size: 20px;
            color: yellow;
        }
        
        /*選中當前指定的元素  數值從1開始*/
        div ul li:nth-child(3){
            font-size: 30px;
            color: purple;
        }
        
        /*n表示選中所有,這里面必須是n, 從0開始的  0的時候表示沒有選中*/
        div ul li:nth-child(n){
            font-size: 40px;
            color: red;
        }
        
        /*偶數*/
        div ul li:nth-child(2n){
            font-size: 50px;
            color: gold;
        }
        /*奇數*/
        div ul li:nth-child(2n-1){
            font-size: 50px;
            color: yellow;
        }
        /*隔幾換色  隔行換色
             隔4換色 就是5n+1,隔3換色就是4n+1
            */
        
        div ul li:nth-child(5n+1){
            font-size: 50px;
            color: red;
        }
            
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM