html - 如何将 :nth-child 用于交替行
问题描述
我想为偶数行设置边框顶部和边框底部的手风琴样式,例如:2、4、6 等。我尝试过,:nth-child
但它没有反映我的父div
元素,但它反映了我的子元素。
代码
<div className="accordion" id="adsdfsdf">
<div className="accordionitem">
<div className="accordion-card">
<div className="accordion-card-header" id="aada">
<h3 className="mb-0 w-100">
<a
className="collapsed"
role="button"
>
<span className="icon-left">
<i className=" a-minus" />
<i className="a-plus" />
</span>
</a>
</h3>
</div>
</div>
</div>
<div className="accordion" id="adsdfsdf">
<div className="accordionitem">
<div className="accordion-card">
<div className="accordion-card-header" id="aada">
<h3 className="mb-0 w-100">
<a
className="collapsed"
role="button"
>
<span className="icon-left">
<i className=" a-minus" />
<i className="a-plus" />
</span>
</a>
</h3>
</div>
</div>
</div>
css
.accordion-card-header {
boder-top: 1px solid red;
border-bottom: 1px solid red;
}
解决方案
你快到了。您需要用于:nth-child(even)
设置偶数行:nth-child(odd)
的样式和奇数行的样式。如需进一步参考,您可以通过nth-child() 选择器
这是一个小演示
div:nth-child(odd) {
height: 100px;
width: 100px;
background: yellow;
margin: 20px auto;
}
div:nth-child(even) {
height: 100px;
width: 100px;
background: green;
border-top: 5px solid black;
border-bottom: 5px solid red;
margin: 20px auto;
}
<div>odd</div>
<div>even</div>
<div>odd</div>
<div>even</div>
推荐阅读
- php - 在根节点内插入一组新节点
- ios - iOS MapKit 获取地点信息和评论
- typescript - 在 typescript 中声明类成员时使用 '=' 和 ':' 的区别
- reactjs - 我如何在反应中改变我的状态
- asp.net-mvc - 禁用 Azure AppFabric 缓存 Asp.Net MVC
- php - 将结束文件夹重定向到没有此文件夹的相同 URL
- html - 将“三行”文本与 html 中的缩进对齐
- ethereum - 为什么 eqzip 众筹中的 GetReward 功能无法转账?
- powershell - Powershell WMI Win32_NetworkAdapterConfiguration EnableDHCP 删除 IP 网关不起作用
- button - JavaFX 按钮 setFont