国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > CSS > 正文

CSS3結(jié)構(gòu)性偽類(lèi)選擇器九種寫(xiě)法

2024-07-11 08:35:58
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

一、X:nth-child(n)

Example Source Code :
 li:nth-child(3) {
color: red;
}

  接下來(lái)的幾個(gè)偽類(lèi)選擇器使用上非常類(lèi)似,功能也比較接近。
  :nth-child(n),用于匹配索引值為n的子元素。索引值從1開(kāi)始。
  X:nth-child()用法實(shí)際上有三種變化,demo的用法是最簡(jiǎn)單的,X:nth-child()更強(qiáng)大的用處在于奇偶匹配,明河不展開(kāi)講,有興趣的請(qǐng)看《Understanding :nth-child Pseudo-class Expressions》,《CSS3 :nth-child()偽類(lèi)選擇器》

二、X:nth-last-child(n)

Example Source Code :
 li:nth-last-child(2) {
color: red;
}

  :nth-child(n),是從第一個(gè)開(kāi)始算索引,而X:nth-last-child(n)是從最后一個(gè)開(kāi)始算索引。

三、X:nth-of-type(n)

Example Source Code:
ul:nth-of-type(3) {
border: 1px solid black;
}

  nth-of-type與nth-child的效果是驚人的相似,想要更多的了解nth-of-type請(qǐng)看《Alternative for :nth-of-type() and :nth-child()》,:nth-of-type(N)

四、X:nth-last-of-type(n) 

Example Source Code :
ul:nth-last-of-type(3) {
border: 1px solid black;
}

  :nth-last-child效果相似。

五、X:first-child 

Example Source Code:
 ul li:first-child {
border-top: none;
}

  匹配子集的第一個(gè)元素。IE7就可以支持了,這個(gè)偽類(lèi)還是非常有用的。

六、X:last-child

 Example Source Code :
ul > li:last-child {
color: green;
}

  與:first-child效果相反
  留意IE8支持:first-child,但不支持:last-child。

七、X:only-child

Example Source Code:
 div p:only-child {
color: red;
}

   這個(gè)偽類(lèi)一般用的比較少,比如上述代碼匹配的是div下的有且僅有一個(gè)的p,也就是說(shuō),如果div內(nèi)有多個(gè)p,將不匹配。

八、X:only-of-type

Example Source Code:
 li:only-of-type {
font-weight: bold;
}
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 鸡东县| 漳浦县| 新兴县| 当雄县| 巴青县| 红桥区| 沙湾县| 景宁| 正宁县| 宝清县| 静海县| 固阳县| 修武县| 洛南县| 凤山市| 健康| 万全县| 丹阳市| 常州市| 裕民县| 凤庆县| 于都县| 静乐县| 墨玉县| 福清市| 莎车县| 潜山县| 封丘县| 冕宁县| 缙云县| 沾益县| 垣曲县| 阿拉善左旗| 龙里县| 兴化市| 新平| 蒙山县| 丹东市| 巢湖市| 岳池县| 靖远县|