【发布时间】:2018-02-13 04:47:39
【问题描述】:
我无法让 nth-child 或 nth-of-type 选择器在 div 列表中生效。
我在一个 React 应用程序中工作,并且有一个组件表示集合中的单个项目,它呈现以下 HTML 结构:
<div className="link-row">
<div className="link-row-header-container">
<div className="header-name"></div>
<div className="header-info"></div>
</div>
<div className="link-container">
<div className="left-inner-container"> //this is the container i'm trying to select
</div>
<div className="right-inner-container">
</div>
</div>
<div className="link-row-footer-container">
<span> footer stuff </span>
</div>
</div>
我在外部组件中有一个函数,将上述组件映射到数据集合上,并将它们放在单个 <div> 中,如下所示:
<div> {linkList} </div>
我正在尝试按三个顺序交替“left-inner-container”的背景颜色,但我始终只获得一种颜色。
这是我的 CSS:
.left-inner-container {
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
border-right-style: solid;
border-right-width: 2px;
border-right-color: #450037;
}
.left-inner-container:nth-of-type(3n+1) {background-color: #ff5e39;}
.left-inner-container:nth-of-type(3n+2) {background-color: #00d2d1;}
.left-inner-container:nth-of-type(3n+3) {background-color: #ffffff;}
【问题讨论】:
标签: css reactjs css-selectors