Target another styled component on hover

后端 未结 5 913
长情又很酷
长情又很酷 2020-12-12 11:42

What is the best way to handle hovers in styled-components. I have a wrapping element that when hovered will reveal a button.

I could implement some state on the com

5条回答
  •  萌比男神i
    2020-12-12 12:02

    This solution worked for me:

    const ContentB = styled.span`
      opacity: 0;
    
      &:hover {
        opacity: 1;
      }
    `
    
    const ContentA = styled.span`
      &:hover ~ ${ContentB} {
        opacity: 1;
      }
    `
    

提交回复
热议问题