伪类选择器之结构选择器::noth-child(n)/:nth-of-type(n)
2016-08-09 21:26
513 查看
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
margin: 50px auto;
width: 400px;
list-style: none outside none;
}
li{
display: inline-block;
margin: 5px;
padding: 5px;
width: 50px;
height: 50px;
font:bold 30px/50px arial;
background: #000;
color: #fff;
border-radius: 50px;
text-align: center;
}
/*:first-child使用*/
ul>li:first-child{
background-color:green ;
}
ul>li:last-child{
background-color: blue;
}
/*:nth-child 与:nth-of-type(n)之间的区别:在特定的区域中查找*/
ul>li:nth-child(3){
background-color: yellow;
}
ul>li:nth-child(2n){
background-color: red;
}
</style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
<li>13</li>
<li>14</li>
<li>15</li>
<li>16</li>
<li>17</li>
<li>18</li>
<li>19</li>
<li>20</li>
</ul>
</body>
</html>
<html>
<head>
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
margin: 50px auto;
width: 400px;
list-style: none outside none;
}
li{
display: inline-block;
margin: 5px;
padding: 5px;
width: 50px;
height: 50px;
font:bold 30px/50px arial;
background: #000;
color: #fff;
border-radius: 50px;
text-align: center;
}
/*:first-child使用*/
ul>li:first-child{
background-color:green ;
}
ul>li:last-child{
background-color: blue;
}
/*:nth-child 与:nth-of-type(n)之间的区别:在特定的区域中查找*/
ul>li:nth-child(3){
background-color: yellow;
}
ul>li:nth-child(2n){
background-color: red;
}
</style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
<li>13</li>
<li>14</li>
<li>15</li>
<li>16</li>
<li>17</li>
<li>18</li>
<li>19</li>
<li>20</li>
</ul>
</body>
</html>
相关文章推荐
- css 伪类选择器 :nth-child(n) 与:nth-of-type(n)的区别
- HTML5基础加强css样式篇(结构化伪类选择器:nth-child和nth-of-type比较)(十二)
- HTML5基础加强css样式篇(结构化伪类选择器:nth-of-type)(十一)
- CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS3选择器:nth-child和:nth-of-type之间的差异(转)
- CSS nth-child、first-child、last-child、nth-of-type、first-of-type和last-of-type选择器使用
- css3中nth-child选择器和nth-of-type选择器的区别
- css伪类选择器之:first-child和:first-of-type
- [css3]CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS3选择器:nth-child和:nth-of-type之间的差异
- css3 - 选择器first-child、last-child、nth-child、nth-last-child、nth-of-type
- CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS3的nth-child() 和nth-of-type()选择器,表格奇偶行变色
- CSS选择器,nth-child 与 nth-of-type 选择器详解
- CSS3伪类选择器:nth-child(n)及:nth-of-type(n)使用区别探究总结
- CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS nth-child、first-child、last-child、nth-of-type、first-of-type和last-of-type选择器使用
- CSS :nth-child与:nth-of-type选择器
- css3之nth-child和nth-of-type