【发布时间】:2021-01-24 22:46:33
【问题描述】:
在按钮悬停时我也想更改 :before 内容,我在官方文档中找不到答案我想知道这是可能的。 这是我要转换为样式化组件语法的 css 选择器:
.button:hover::before{}
这是样式化组件:
import styled from '@emotion/styled'
export const Button =styled.button(props=>{
return`
padding: .75rem 2rem ;
color: #fff;
background-color: transparent;
border: 1px solid #000;
position: relative;
z-index: 1;
transition: all .5s cubic-bezier(0.785, 0.135, 0.15, 0.86);
cursor: pointer;
width: ${props.width ? props.width:'fit-content'};
margin-top: ${props.marginTop ? props.marginTop :0}rem;
&:before{
content: '';
position: absolute;
z-index: -1;
height: 100%;
width: 100%;
top: 0;
left: 0;
${props.collection?"background-color: #fff;":"background-color: var(--colorGrey);"}
transition: all .5s cubic-bezier(0.785, 0.135, 0.15, 0.86);
transform-origin: left center;
//I want to change style on hover
}
&:hover{
color:var(--colorGrey);
}
`})
【问题讨论】:
标签: reactjs styled-components emotion