亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

CSS 偽類

CSS 偽類(Pseudo-classes)

CSS偽類是用來添加一些選擇器的特殊效果。


語法

偽類的語法:

selector:pseudo-class {property:value;}

CSS類也可以使用偽類:

selector.class:pseudo-class {property:value;}


anchor偽類

在支持 CSS 的瀏覽器中,鏈接的不同狀態(tài)都可以以不同的方式顯示。在我們的css鏈接里面我們我們已經(jīng)了解了一點

實例

      <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>php中文網(wǎng)(php.cn)</title>
    <style>
        a:link {color:#FF0000;}    /* 未訪問的鏈接 */
        a:visited {color:#00FF00;} /* 已瀏覽過的鏈接 */
        a:hover {color:#FF00FF;}   /* 鼠標(biāo)劃過的鏈接 */
        a:active {color:#0000FF;}  /* 已選中的鏈接 */
    </style>
</head>

<body>
<p><b><a href="" target="_blank">這是一個鏈接</a></b></p>
<p><b>注意:</b> a:hover 必須在 a:link 和 a:visited 之后,需要嚴(yán)格按順序才能看到效果。</p>
<p><b>注意:</b> a:active 必須在 a:hover 之后。</p>
</body>
</html>

注意: a:hover 必須在 a:link 和 a:visited 之后,需要嚴(yán)格按順序才能看到效果。

注意: a:active 必須在 a:hover 之后。

注意:偽類的名稱不區(qū)分大小寫。

運行程序嘗試一下


偽類和CSS類

偽類可以與 CSS 類配合使用:

a.red:visited {color:#FF0000;}

<a class="red" href="css-syntax.html ">CSS Syntax</a>

如果在上面的例子的鏈接已被訪問,它會顯示為紅色。


實例

使用 :focus

  <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>php中文網(wǎng)(php.cn)</title>
    <style>
        input:focus
        {
            background-color:yellow;
        }
    </style>
</head>

<body>
<form action="" method="get">
    姓名: <input type="text" name="fname" /><br>
    留言: <input type="text" name="content" /><br>
    <input type="submit" value="Submit" />
</form>


</body>
</html>

運行程序嘗試一下


所有CSS偽類/元素

選擇器示例示例說明
:checkedinput:checked選擇所有選中的表單元素
:disabledinput:disabled選擇所有禁用的表單元素
:emptyp:empty選擇所有沒有子元素的p元素
:enabledinput:enabled選擇所有啟用的表單元素
:first-of-typep:first-of-type選擇每個父元素是p元素的第一個p子元素
:in-rangeinput:in-range選擇元素指定范圍內(nèi)的值
:invalidinput:invalid選擇所有無效的元素
:last-childp:last-child選擇所有p元素的最后一個子元素
:last-of-typep:last-of-type選擇每個p元素是其母元素的最后一個p元素
:not(selector):not(p)選擇所有p以外的元素
:nth-child(n)p:nth-child(2)選擇所有p元素的第二個子元素
:nth-last-child(n)p:nth-last-child(2)選擇所有p元素倒數(shù)的第二個子元素
:nth-last-of-type(n)p:nth-last-of-type(2)選擇所有p元素倒數(shù)的第二個為p的子元素
:nth-of-type(n)p:nth-of-type(2)選擇所有p元素第二個為p的子元素
:only-of-typep:only-of-type選擇所有僅有一個子元素為p的元素
:only-childp:only-child選擇所有僅有一個子元素的p元素
:optionalinput:optional選擇沒有"required"的元素屬性
:out-of-rangeinput:out-of-range選擇指定范圍以外的值的元素屬性
:read-onlyinput:read-only選擇只讀屬性的元素屬性
:read-writeinput:read-write選擇沒有只讀屬性的元素屬性
:requiredinput:required選擇有"required"屬性指定的元素屬性
:rootroot選擇文檔的根元素
:target#news:target選擇當(dāng)前活動#news元素(點擊URL包含錨的名字)
:validinput:valid選擇所有有效值的屬性
:linka:link選擇所有未訪問鏈接
:visiteda:visited選擇所有訪問過的鏈接
:activea:active選擇正在活動鏈接
:hovera:hover把鼠標(biāo)放在鏈接上的狀態(tài)
:focusinput:focus選擇元素輸入后具有焦點
:first-letterp:first-letter選擇每個<p> 元素的第一個字母
:first-linep:first-line選擇每個<p> 元素的第一行
:first-childp:first-child選擇器匹配屬于任意元素的第一個子元素的 <]p> 元素
:beforep:before在每個<p>元素之前插入內(nèi)容
:afterp:after在每個<p>元素之后插入內(nèi)容
:lang(language)p:lang(it)為<p>元素的lang屬性選擇一個開始值




Weiter lernen
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> input:focus { background-color:yellow; } </style> </head> <body> <form action="" method="get"> 姓名: <input type="text" name="fname" /><br> 留言: <input type="text" name="content" /><br> <input type="submit" value="Submit" /> </form> </body> </html>
einreichenCode zurücksetzen