티스토리 뷰

.parent {
width:300px;
height:300px;
background:#eee;
}

.child {
width:50px;
height:50px;
background:#fff;
}


.parent:hover .child{
background:#000
}

부모태그(parent)에게 hover 시 자식태그(child) 의 background color 가 바뀌는 css

이를 react 의 styled component 에서 사용시

 

const Child = styled.div`
  width:50px;
  height:50px;
  background:#fff;
`

const Parent = styled.div`
  width:300px;
  height:300px;
  background:#eee;
  
  &:hover ${Child}{
  background:#000;
  }
`;

SCSS 식으로 작성 가능하다.

위와같이 다른 styled component 를 참조할 수 있다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함