栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

:nth

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

:nth

您误会了选择器。它选择的元素也是,

:nth-child(n)
该元素 也具有 前面的元素作为父元素。

如果前面没有选择器,则默认为

*:nth-child(n)

因为您可能只想将其应用于直接后代,而不是将每个元素应用于其父代的第四个子代和父代的后代,所以我

.element > *:nth-child(n)
只能将其应用于直接后代。

div#wrap > *:nth-child(4) {  border-bottom: 2px solid orange;}div#wrap > *:nth-child(4) {  border-bottom: 2px solid orange;}<div id="wrap">  <h1>Heading 1</h1>  <p>This is a test!</p>  <h2>Creating content</h2>  <p>The next paragraph uses the <strong>.html</strong> method to create a new element.</p></div>

如果您想更加具体,并且仅选择第四个子

<p>
元素,则可以使用
.element > p:nth-child(n)
。这将选择所有
<p>
div#wrap
选择器匹配的元素的第四个直接后代的元素。

div#wrap > p:nth-child(4) {  border-bottom: 2px solid orange;}div#wrap > p:nth-child(4) {  border-bottom: 2px solid orange;}<div id="wrap">  <h1>Heading 1</h1>  <p>This is a test!</p>  <h2>Creating content</h2>  <p>The next paragraph uses the <strong>.html</strong> method to create a new element.</p></div>

如果要选择

<p>
直接从each降序的第二个元素
div#wrap
,可以这样使用
.element > p:nth-of-type(n)

div#wrap > p:nth-of-type(2) {  border-bottom: 2px solid orange;}div#wrap > p:nth-of-type(2) {  border-bottom: 2px solid orange;}<div id="wrap">  <h1>Heading 1</h1>  <p>This is a test!</p>  <h2>Creating content</h2>  <p>The next paragraph uses the <strong>.html</strong> method to create a new element.</p></div>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/370531.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号