我试图通过将其作为孩子的目标来改变元素的nth-child(2)背景颜色,但我似乎无法让它工作,我尝试了不同元素的多种变化,似乎没有任何工作ColorBoxImgGrid
如果我不尝试定位nth-child元素,这将改变背景颜色
const ImgGrid = styled.div`
display: flex;
flex-wrap: wrap;
flex-direction: row;
${ColorBox} {
background: #ff00ff;
}
`
Run Code Online (Sandbox Code Playgroud)
我怎样才能针对nth-child(2)中的 ColorBox元素?
import React from 'react'
import styled from 'styled-components'
// import Img from '../../atoms/Img'
import { array, bool } from 'prop-types'
const Wrap = styled.div`
padding: 20px 0;
`
const BoxWrap = styled.div`
position: relative;
border: 1px solid #000;
height: auto;
padding: 20px;
`
const Title = styled.div`
position: absolute;
display: flex; …Run Code Online (Sandbox Code Playgroud)