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

首頁 > 開發(fā) > CSS > 正文

CSS3結構性偽類選擇器九種寫法

2024-07-11 08:48:06
字體:
來源:轉載
供稿:網友

一、X:nth-child(n)

Example Source Code
 li:nth-child(3) {
color: red;
}
  接下來的幾個偽類選擇器使用上非常類似,功能也比較接近。
  :nth-child(n),用于匹配索引值為n的子元素。索引值從1開始。
  X:nth-child()用法實際上有三種變化,demo的用法是最簡單的,X:nth-child()更強大的用處在于奇偶匹配,明河不展開講,有興趣的請看《Understanding :nth-child Pseudo-class Expressions》,《CSS3 :nth-child()偽類選擇器》

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

Example Source Code
 li:nth-last-child(2) {
color: red;
}
  :nth-child(n),是從第一個開始算索引,而X:nth-last-child(n)是從最后一個開始算索引。

三、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請看《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;
}
  匹配子集的第一個元素。IE7就可以支持了,這個偽類還是非常有用的。

六、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;
}
   這個偽類一般用的比較少,比如上述代碼匹配的是div下的有且僅有一個的p,也就是說,如果div內有多個p,將不匹配。

八、X:only-of-type

Example Source Code
 li:only-of-type {
font-weight: bold;
}
  與:only-child類似。

九、X:first-of-type

Example Source Code
ul:first-of-type{
font-weight: bold;
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 吴旗县| 平陆县| 万宁市| 万全县| 广宗县| 绥江县| 张家港市| 新巴尔虎左旗| 武定县| 石家庄市| 石门县| 北辰区| 卢氏县| 钟山县| 福清市| 舒兰市| 盐山县| 永年县| 蕲春县| 夏邑县| 白山市| 龙川县| 桃园市| 荔波县| 隆林| 镇雄县| 屯留县| 沈丘县| 上犹县| 汝城县| 舞阳县| 高雄市| 白河县| 攀枝花市| 平山县| 屏东县| 密山市| 财经| 湘潭县| 盐山县| 广水市|