Closed2

Gridで偶数のアイテムだけmargin入れたい。styled componentsで

nori0__nori0__

これでOK。
&:nth-child(2)だとStatements自身の偶数番目の要素を指してしまう。

import styled from 'styled-components';

export const Statement = styled.div`
  white-space: pre-wrap;
  word-wrap: break-word;
`;

export const Statements = styled.div`
  display: grid;
  flex-direction: column;
  justify-content: flex-start;
  align-items: start;
  ${Statement}:nth-child(2n) {
    margin-bottom: 1rem;
  }
`;

https://stackoverflow.com/questions/48713421/target-child-element-styled-components

このスクラップは2022/05/15にクローズされました