[英]Styled Components - hover not working with template strings
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>
)
const Parent = styled('div')`
position: relative;
margin-bottom: 0;
&:hover > div {
display: flex;
cursor: pointer;
background-color: pink;
}
`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.