当前位置:网站首页>Nth child selector
Nth child selector
2022-06-09 16:11:00 【zhuimengchizixinwx】
| Selectors | describe |
|---|---|
| ul li:first-child | Choose ul The first of the parent elements li Subelement |
| ul li:last-child | Choose ul The last child element in the parent element |
| ul li:nth-child(n) | Choose ul The second of the parent elements n Sub elements |
| ul li:nth-child(odd) | Select the... With odd subscript li Elements |
| ul li:nth-child(even) | Select... With even subscript li Elements |
| ul li:nth-child(2n) | Select... With even subscript li Elements (n For natural Numbers The initial value is 0 successively +1 Increasing ,2n Said is 20=0 21=2 22=4 23=6 24=8 25=10 This will continue to increase ) |
| ul li:nth-child(3n+1) | Selected as 1 4 7 10 Subscripts in this order li Elements (n For natural Numbers The initial value is 0 successively +1 Increasing ,3n+1 Said is 30+1=1 31+1=4 3*2+1=7 This will continue to increase ) |
| ul li:nth-child(-n+5) | Select the first five li Elements (n For natural Numbers The initial value is 0 successively -1 Increasing ,-n+5 Said is 5+0=5 5+[-1]=4 5+[-2]=3 This will continue to increase ) |
| ul li:nth-child(n+5) | Select the fifth one li Elements (n For natural Numbers The initial value is 0 successively +1 Increasing ,n+5 Said is 5+0=5 5+1=6 5+2=7 This will continue to increase ) |
| ul li:nth-last-child(n) | Choose ul The penultimate in the parent element n Sub elements |
| ul li:first-of-type | Choose ul The type in the parent element is li The first element of |
| ul li:last-of-type | |
| ul li:nth-of-type(n) | Choose ul The type in the parent element is li Of the n Elements |
| ul li:nth-last-of-type(n) | Choose ul The type in the parent element is li The last of n Elements |
notes :nth-child: Is not a filter type , But you have to match the type selector to make it work
ul li:nth-child(1){background: #009A00;}
/* There's one down there span So the first one is span, however span and li It doesn't work because it doesn't work */
/* Want to use :nth-child Select the first one li Have to write ul li:nth-child(2)*/
<div id="box">
<span></span>
<li></li>
<li></li>
<li></li>
<li></li>
</div>
notes :nth-of-type(n): Filter the type first , Determine the number of elements
ul li:nth-of-type(1){background: #009A00;} /* To filter out span after , Get the first li Elements */
<div id="box">
<span></span>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</div>
nth-child: Structure pseudo class selector details :
1. Choose ul The first of the parent elements li Subelement
ul li:first-child{background: #009A00;}
2. Choose ul The last child element in the parent element
ul li:last-child{background: #009A00;}
3. Choose ul The second of the parent elements 5 Sub elements
ul li:nth-child(5){background: #009A00;}
4. Select the... With odd subscript li Elements
ul li:nth-child(odd){background: #009A00;}
5. Select... With even subscript li Elements
ul li:nth-child(even){background: #009A00;}
6. Select the... With odd subscript li Elements
ul li:nth-child(2n-1){background: #009A00;}
7. Select... With even subscript li Elements
ul li:nth-child(2n){background: #009A00;}
8. Choose ul The penultimate in the parent element 2 Sub elements
ul li:nth-last-child(2){background: #009A00;}
9. Choose ul The type in the parent element is li The first element of
ul li:first-of-type{background: #009A00;}
10. Choose ul The type in the parent element is li Of the 5 Elements
ul li:nth-of-type(5){background: #009A00;}
CSS2 Attribute selector :
| Selectors | Example | describe |
|---|---|---|
| [attr] | [name] | Selected name Attribute elements |
| [attr=val] | [name=box] | Selected name Property whose value is box also neme There are only attribute values box The element of this one |
| [attr~=val] | [name~=box] | Selected name Property and its value is a list of words , contain box The value of the elements |
[name]{background: #009A00;} /* Set the background of the selected element to green */
<div id="unp">
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li name="box"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
</div>
design sketch :
2. Selected name Property whose value is box also neme There are only attribute values box The element of this one
[name=box]{background: #009A00;} /* Set the background of the selected element to green */
<div id="unp">
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li name="box"></li>
<li name="box erp"></li> /* This name There are two values , This will not be selected */
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
</div>
design sketch :
3. Selected name Property and its value contains box The value of the elements
[name~=box]{background: #009A00;}
<div id="unp">
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li name="box"></li>
<li name="box erp"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
</div>
design sketch :
CSS3 Attribute selector :
| Selectors | Example | describe |
|---|---|---|
| [attr^=val] | [class^=box] | Selected class Property and its value is in the form of box Elements at the beginning |
| [attr$=box] | [name$=box] | Selected class Property and its value is in the form of box Ending element |
| [attr*=box] | [name*=box] | Selected class Property and its value contains box The elements of |
| CSS3 Detailed explanation of attribute selector cases : | ||
| 1. Selected class Property and its value is in the form of box Elements at the beginning |
[class^=box]{background: #009A00;}
<div id="unp">
<li class="box1"></li>
<li class="box2"></li>
<li class="box3"></li>
<li class="box4"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
</div>
design sketch :
2. Selected class Property and its value is in the form of box Ending element
[class$=box]{background: #009A00;}
<div id="unp">
<li class="un-box"></li>
<li class="un-box"></li>
<li class="un-box"></li>
<li class="un-box"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
</div>
design sketch :
3. Selected class Property and its value contains box The elements of
[class*=box]{background: #009A00;}
<div id="box">
<li class="unboxp"></li>
<li class="unboxp"></li>
<li class="unboxp"></li>
<li class="unboxp"></li>
<li class="unboxp"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
<li class="ure"></li>
</div>
design sketch :
Pseudo class attribute selector :
| Selectors | Example | describe |
|---|---|---|
| :disabled | input:disabled{ border: 2px solid red;} | Select the disabled form element |
| :enabled | input:enabled{ border: 2px solid red;} | Select the form element with available status |
| :checked | input:checked{width: 50px;height: 50px;} | Select the single and multiple check boxes in the selected status |
| ::selection | input::selection { color: red;} | Selected elements ( Generally for text |
边栏推荐
- What is the difference between IPS screen and LED screen
- Dotnet core releases only necessary dependent files
- May training (day 30) - topology sorting
- WPS how to unhide cell worksheets
- 字节一面:网站显示不出来,怎么排查?
- Experience sharing of technical we media realization -- starting to try to make CSDN's reply one year later
- 接口测试系列——AutoDiff流量回放在集成测试中的实践应用
- May training (day 22) - orderly gathering
- Qscrollarea use tutorial to realize the setting interface that can slide up and down
- dotnet core 发布只带必要的依赖文件
猜你喜欢

Analysis of variable hiding security in contract security

如何高效学习 思维导图

《CSDN 涨粉攻略》11个涨粉方法,你学会了几个?

Differences between containers and mirrors

直播预告 | 社交新纪元,共探元宇宙社交新体验

JWT思维导图

The demand for data storage is increasingly diversified, and it is a general trend to divide and conquer

SaaS tenant multi store system in the catering industry accelerates the digital operation of catering and realizes cost reduction and efficiency increase

内存数据库究竟是如何发挥内存优势的?

Conference control keyboard instructions for ≥ 3.5-inch LCD screen
随机推荐
五月集训(第28天) —— 动态规划
五月集训(第22天) —— 有序集合
Byte side: how to check if the website cannot be displayed?
My Lord, times have changed...
Zhouweilin, founder of aloudata: open the door of data platform reform with noetl
单体应用和微服务调用区别
64 interface appearance (window without border, irregular form, transparent form)
Kubernetes 核心概念
May training (day 31) - status compression
R语言使用aov函数进行双因素方差分析(Two-way factorial ANOVA)、gplots包的plotmeans函数在双因素方差分析中显示交互作用、包括均值,误差条、95%置信区间、样本量
May training (day 24) - segment tree
Data security is urgent. What is the significance of the first SOC 2 authentication report for domestic intelligent manufacturers?
67 2D drawing (antialiasing drawing / antialiasing rendering)
Start using dapr
一个时代的终结!吴恩达经典《机器学习》课程本月关闭注册...然而
合约安全之-变量隐藏安全问题分析
五月集训(第25天) —— 树状数组
LeetCode 327. 区间和的个数
LINQ left join example
Garymarcus publicly shouted that Hinton and musk: deep learning is like hitting the wall. I bet 100000 dollars