0

I've got a styled component that I want to change the background color of when its parent is hovered. right now the hover effect does nothing and I'm not sure why.

const Parent = styled('div')`
    position: relative;
    margin-bottom: 0;
`

const Overlay = styled('div')`
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    z-index: 10;
    margin: 0;
    left: 0;
    right: 0;
    top: 65%;;
    background-color: rgba(128, 34, 69, 0.9);
    ${Parent}:hover & {
        display: flex;
        cursor: pointer;
        background-color: pink;
    }
`

return(
    <div>
        <Parent>
        <Overlay />
        </Parent>
    </div>
)
Luke
  • 3
  • 4

1 Answers1

0
const Parent = styled('div')`
    position: relative;
    margin-bottom: 0;
    &:hover > div {
        display: flex;
        cursor: pointer;
        background-color: pink;
    }
`
William Wang
  • 8,051
  • 3
  • 5
  • 28
  • Thanks William - that only effects the parent. The problem I'm having is changing the background of the child when the parent is hovered. – Luke Nov 10 '20 at 09:28
  • what is child? AFAIK, you are gonna change the background when hover on – William Wang Nov 10 '20 at 13:52