欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          css怎么給指定第幾個li加樣式

          4種方法:1、用“:first-child”給第1個li加樣式,語法“l(fā)i:first-child{樣式代碼}”;2、用“:last-child”給最后1個li加樣式,語法“l(fā)i:last-child{樣式}”;3、用“l(fā)i:nth-of-type(N){樣式代碼}”給第N個li加樣式;4、用“l(fā)i:nth-child(N){樣式代碼}”給第N個li加樣式。

          css怎么給指定第幾個li加樣式

          前端(vue)入門到精通課程:進(jìn)入學(xué)習(xí)

          本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。

          css選取指定第幾個li并加樣式

          方法1:使用:first-child選擇器給第1個li加樣式

          :first-child 選擇器匹配其父元素中的第一個子元素。

          <!DOCTYPE html> <html>  	<head> 		<meta charset="UTF-8"> 		<style> 			li{ 				float: left; 				height: 50px; 				line-height: 50px; 				width: 50px; 				margin: 20px; 				background: #ccc; 				text-align: center; 				color: #fff; 			} 			li:first-child{ 				background:red; 			} 		</style> 	</head>  	<body> 		<ul class="dom"> 			<li>1</li> 			<li>2</li> 			<li>3</li> 			<li>4</li> 			<li>5</li> 		</ul> 	</body>  </html>

          css怎么給指定第幾個li加樣式

          方法2:使用:last-child選擇器給最后1個li加樣式

          :last-child選擇器用來匹配父元素中最后一個子元素。

          li:last-child{ 	background:pink; }

          css怎么給指定第幾個li加樣式

          方法3:使用:nth-of-type()選擇器給第N個li加樣式

          :nth-of-type(n) 選擇器匹配屬于父元素的特定類型的第 N 個子元素的每個元素

          li:nth-of-type(1){  /* 第1個li加樣式 */ 	background:red; } li:nth-of-type(2){  /* 第2個li加樣式 */ 	background:pink; } li:nth-of-type(3){  /* 第3個li加樣式 */ 	background:green; }

          css怎么給指定第幾個li加樣式

          ()內(nèi)的參數(shù)可以是公式或關(guān)鍵字Odd(奇數(shù)) 和 even(偶數(shù))

          n+2從第2個元素開始加樣式。

          li:nth-of-type(n+2){ 	background:red; }

          css怎么給指定第幾個li加樣式

          同理如果選中單數(shù)元素那么就是2n+1(或者使用odd);如果是想選中雙數(shù)元素,那么就應(yīng)該寫成2n+2(或者使用even);

          li:nth-of-type(2n+1){ background:pink; } li:nth-of-type(even){ background:green; }

          css怎么給指定第幾個li加樣式

          方法4:使用:nth-child()選擇器給第N個li加樣式

          :nth-child(n) 選擇器匹配屬于其父元素的第 N 個子元素,不論元素的類型。

          li:nth-child(1){  /* 第1個li加樣式 */ 	background:red; } li:nth-child(3){  /* 第3個li加樣式 */ 	background:pink; } li:nth-child(5){  /* 第5個li加樣式 */ 	background:green; }

          css怎么給指定第幾個li加樣式

          ()內(nèi)的參數(shù)可以是公式或關(guān)鍵字Odd(奇數(shù)) 和 even(偶數(shù))

          li:nth-child(odd){  	background:red; } li:nth-child(2n+2){ background:pink; }

          css怎么給指定第幾個li加樣式

          (學(xué)習(xí)視頻分享:web前端)

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號