css3的偽類有哪些
css3偽類別有:「:first-of-type」、「:last-of-type」、「:only-of-type」、「:only-child」、「:last-child 」、「:root」、「:empty」、「:target」、「:not」等。
本教學操作環境:windows7系統、CSS3&&HTML5版、Dell G3電腦。
css3的偽類別
#選擇器 | 範例 | 範例說明 | CSS |
---|---|---|---|
:first-of-type | p:first-of-type | 選擇每個p元素是其父級的第一個p元素 | 3 |
:last-of-type | p:last-of-type | ##選擇每個p元素是其父級的最後一個p元素 | 3 |
#:only-of-type | #p :only-of-type | 選擇每個p元素是其父級的唯一p元素 | #3 |
:only-child | p:only-child | 選擇每個p元素是其父級的唯一子元素 | #3 |
:nth- child(n) | p:nth-child(2) | #選擇每個p元素是其父級的第二個子元素 | 3 |
:nth-last-child(n) | p:nth-last-child(2) | 選擇每個p元素的是其父級的第二個子元素,從最後一個子項計數 | 3 |
:nth-of-type(n) | p:nth-of-type(2) | 選擇每個p元素是其父級的第二個p元素 | 3 |
:nth-last-of-type(n) | p:nth-last-of-type(2) | 選擇每個p元素的是其父級的第二個p元素,從最後一個子項計數 | 3 |
:last-child | p:last-child | 選擇每個p元素是其父級的最後一個子級。 | 3 |
:root | :root | #選擇文件的根元素 | 3 |
:empty | p:empty | 選擇每個沒有任何子層級的p元素(包含文字節點) | 3 |
:target | #news:target | 選擇目前活動的#news元素(包含該錨名稱的點擊的URL) | 3 |
:enabled | input:enabled | 選擇每個已啟用的輸入元素 | 3 |
:disabled | input:disabled | 選擇每一個已停用的輸入元素 | 3 |
:checked | input:checked | 選擇每個選取的輸入元素 | 3 |
:not( selector) | :not(p) | 選擇每個並非p元素的元素 | 3 |
:out-of-range | 匹配值在指定區間之外的input元素 | #3 | |
:in-range | 符合值在指定區間之內的input元素 | 3 | |
:read-write | 用於匹配可讀及可寫入的元素 | 3 | |
:read-only | 用於匹配設定"readonly"(唯讀)屬性的元素 | ##3||
:optional | 用於符合可選的輸入元素 | 3 | |
:required | 用來符合設定了"required" 屬性的元素 | #3 | |
用來符合輸入值為合法的元素 | 3 | #:invalid | |
用於匹配輸入值為非法的元素 | 3 |
Let’s learn about some css3 pseudo-classes through examples. :first-of-type Select all elements that are the first child element of a specific type from their parent element <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p:first-of-type").css("background-color","pink"); }); </script> </head> <body> <p>p</p> <div> <p>p1</p> <p>p2</p> </div><br> <div> <span>span</span> <p>p1</p> <p>p2</p> </div> </body> </html> 登入後複製 ##:last-of-type Selects the last element of a specific type that belongs to its parent element All elements of a child element<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p:last-of-type").css("background-color","pink"); }); </script> </head> <body> <div> <p>p1</p> <p>p2</p> </div><br> <div> <p>p1</p> <p>p2</p> <span>span</span> </div> </body> </html> 登入後複製 ##: only-of-typeSelect all elements that are the only child element of a specific type from their parent element <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p:only-of-type").css("background-color","pink"); }); </script> </head> <body> <div style="border:1px solid;"> <p>p1</p> <p>p2</p> </div><br> <div style="border:1px solid;"> <p>p</p> </div><br> <div style="border:1px solid;"> <span>span</span> <p>p</p> </div><br> </body> </html> 登入後複製 Select every element that is the only child element of its parent element <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p:only-child").css("background-color","pink"); }); </script> </head> <body> <div style="border:1px solid;"> <p>p1</p> <p>p2</p> </div><br> <div style="border:1px solid;"> <p>p</p> </div><br> <div style="border:1px solid;"> <p>p1</p> <p>p2</p> </div><br> </body> </html> 登入後複製
Select all elements that are the nth child element of any type of its parent element
Selects all elements that are the nth child element of any type that belongs to its parent element, counting from the last child element. :nth-of-type(n)Select all elements that are the nth child element of a specific type of their parent element <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p:nth-of-type(3)").css("background-color","pink"); }); </script> </head> <body> <h1>body h1</h1> <p>body p1</p> <p>body p2(body 的第三个子元素)。</p> <div style="border:1px solid;"> <span>div span </span> <p>div p1</p> <p>div p2(div 的第三个子元素)</p> <p>div p3。</p> </div><br> <div style="border:1px solid;"> <p>div2 p1</p> <p>div2 p2</p> <p>div2 p3(div 的第三个子元素)</p> </div> <p>body p3</p> </body> </html> 登入後複製 :nth-last-of-type#Selects all elements that are the nth child element of a specific type that belongs to its parent element, starting with the last child element Start counting <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p:nth-last-of-type(3)").css("background-color","pink"); }); </script> </head> <body> <h1>body h1</h1> <p>body p1</p> <p>body p2(body 的第三个子元素)。</p> <div style="border:1px solid;"> <span>div span </span> <p>div p1</p> <p>div p2(div 的第三个子元素)</p> <p>div p3。</p> </div><br> <div style="border:1px solid;"> <p>div2 p1</p> <p>div2 p2</p> <p>div2 p3(div 的第三个子元素)</p> </div> <p>body p3</p> </body> </html> 登入後複製
(Learning video sharing: |
以上是css3的偽類有哪些的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

純CSS3怎麼實現波浪效果?這篇文章就來跟大家介紹一下使用 SVG 和 CSS 動畫來製作波浪效果的方法,希望對大家有幫助!

兩種方法:1、利用display屬性,只要為元素加上「display:none;」樣式即可。 2.利用position和top屬性設定元素絕對定位來隱藏元素,只需為元素加上「position:absolute;top:-9999px;」樣式。

在css中,可以利用border-image屬性來實作花邊邊框。 border-image屬性可以使用圖片來建立邊框,即給邊框加上背景圖片,只需要將背景圖片指定為花邊樣式即可;語法「border-image: url(圖片路徑) 向內偏移值圖像邊界寬度outset 是否重複;」。

實作方法:1、使用「:active」選擇器選取滑鼠點擊圖片的狀態;2、使用transform屬性和scale()函數實現圖片放大效果,語法「img:active {transform: scale(x軸放大倍率,y軸放大倍率);}」。

怎麼製作文字輪播與圖片輪播?大家第一想到的是利用js,其實利用純CSS也能實現文字輪播與圖片輪播,下面來看看實作方法,希望對大家有幫助!

在css3中,可以利用「animation-timing-function」屬性來設定動畫旋轉速度,該屬性用於指定動畫將如何完成一個週期,設定動畫的速度曲線,語法為「元素{animation-timing-function:速度屬性值;}」。

使用:nth-child(n+3)偽類選擇器選擇位置大於等於3的子元素的樣式,具體程式碼範例如下:HTML程式碼:<divid="container"><divclass="item"> ;第一個子元素</div><divclass="item"&
