02、CSS3结构选择器
2016-08-02 09:08
459 查看
:nth-child 选择指定索引处的子元素
nth-child(n) 父元素下的第n个子元素
nth-child(odd)奇数子元素(同nth-child(2n-1))
nth-child(even)偶数子元素(同nth-child(2n))
nth-child(an+b)公式
:nth-last-child(n) 倒数第n个子元素
:nth-of-type(n) 父元素下的第n个指定类型的子元素
:nth-last-of-type 父元素下的倒数第n个指定类型的子元素
:first-child 选择父元素下的第一个子元素
:last-child 选择父元素下的最后一个子元素
:only-child 选择父元素下唯一的子元素
:only-of-type选择父元素下指定类型的唯一子元素
:root 选择文档的根目录,返回html
nth-child(n) 父元素下的第n个子元素
nth-child(odd)奇数子元素(同nth-child(2n-1))
nth-child(even)偶数子元素(同nth-child(2n))
nth-child(an+b)公式
:nth-last-child(n) 倒数第n个子元素
:nth-of-type(n) 父元素下的第n个指定类型的子元素
:nth-last-of-type 父元素下的倒数第n个指定类型的子元素
:first-child 选择父元素下的第一个子元素
:last-child 选择父元素下的最后一个子元素
:only-child 选择父元素下唯一的子元素
:only-of-type选择父元素下指定类型的唯一子元素
:root 选择文档的根目录,返回html
<!doctype html><!--声明当前文档为html文档--> <html lang="en"><!--语言为英语--> <head><!--头部--> <meta charset="UTF-8"><!--字符编码:utf-8国际编码 gb2312中文编码--> <meta name="Keywords" content="关键词"> <meta name="Description" content="描述"> <title>Document</title> <style>/*css样式表的衣柜*/ *{margin:0px;padding:0px;}/*去除默认外边距、内边距*/ p{height:30px;background:#cc9966;margin-top:10px;} /* :nth-child(n) 父元素下的第n个子元素 */ div.wrap p:nth-child(1){ width:200px;background:red; } div.wrap p:nth-child(5){ background:red; } div.wrap div:nth-child(7){ background:#aaa;height:50px; } /* :nth-child(odd)奇数子元素(同nth-child(2n-1)) */ /* div.wrap div:nth-child(7){ background:#aaa;height:50px; } div.wrap p:nth-child(odd){ width:200px;background:red; } */ /* :nth-child(even)偶数子元素(同nth-child(2n)) */ /* div.wrap p:nth-child(even){ width:200px;background:red; } */ /* :nth-child(an+b)公式 */ /* div.wrap p:nth-child(3n+3){ width:200px;background:red; } */ /* :nth-last-child(n) 倒数第n个子元素 */ /* div.wrap p:nth-last-child(1){ width:200px;background:red; } */ /* :nth-last-child(n) 倒数第n个子元素 */ /* div.wrap p:nth-last-child(1){ width:200px;background:red; } */ /* :nth-of-type(n) 父元素下的第n个指定类型的子元素 */ /* div.wrap div:nth-of-type(2){ width:200px;background:red; } */ /* :nth-last-of-type(n) 父元素下的倒数第n个指定类型的子元素 */ /* div.wrap div:nth-last-of-type(2){ width:200px;background:red; } */ </style> </head> <body><!--身体--> <div class="wrap"> <p>1</p> <p>2</p> <p>3</p> <p>4</p> <p>5</p> <p>6</p> <div>7</div> <div>8</div> <div>9</div> <div>10</div> <p>11</p> <p>12</p> <p>13</p> <p>14</p> <p>15</p> </div> </body> </html>
相关文章推荐
- Css3(02)使用选择器插入内容(before/after)
- CSS3学习笔记 之 结构伪类选择器
- css3中的结构伪类选择器
- CSS3之选择器1(属性选择器,结构伪类)
- CSS3中结构伪类选择器——root、not、empty、target选择器
- CSS3中结构伪类选择器——root、not、empty、target选择器
- HTML5中CSS3的结构伪类选择器
- 02.Web大前端时代之:HTML5+CSS3入门系列~H5结构元素
- css3 总结02
- vue学习02 vue-cli 模板创建后的基本结构 及内容组件 指令
- CSS3的新增选择器示例-属性选择器
- 18/1/23.HTML5/CSS3的学习(五)——HTML5结构实战案例
- 树结构02—— 平衡二叉树
- [css3]CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS3选择器
- 02-线性结构3 Reversing Linked List (25分)
- 02Linux文件系统基本结构
- CSS3的4大伪元素选择器详解
- 02-线性结构2 Reversing Linked List (25分)
- PTA 02-线性结构2 一元多项式的乘法与加法运算