我有一个组件,它是一个样式为div的组件,在悬停时会变绿:
const ProjectAdd= styled.div`
background-color: white;
list-style-type: none;
list-style: none;
height: 100%;
width: 10%;
height: 100%;
border-radius: .4em;
display: flex;
justify-content: center;
align-items: center;
outline: 10px #7d7d7d99;
box-shadow: 3px 5px 15px -4px #999999;
transition: .5s all;
&:hover{
background-color: #00935f61;
color: "white";
}
`这一点在我的构成部分中显示为:
<ProjectAdd>
<Typography fontSize=".85em" color="#009360">
+ Add
</Typography>
</ProjectAdd>当这个悬停时,我希望我的排版变成白色。在没有样式{{}的情况下,我将如何在排版中进行悬停?
发布于 2022-08-17 15:50:41
主要有两种选择。
选项1:使用sx支柱
<ProjectAdd>
<Typography
fontSize=".85em"
color="#009360"
sx={{ "&:hover": { color: "white" } }}
>
+ Add
</Typography>
</ProjectAdd>
当你提到“没有样式{{}}”时,这可能正是你想要避免的,所以另一个选择是.
选项2:目标&:hover .MuiTypography-root在ProjectAdd样式中
import styled from "@emotion/styled";
import Typography from "@mui/material/Typography";
const ProjectAdd = styled.div`
background-color: white;
list-style-type: none;
list-style: none;
height: 100%;
width: 10%;
height: 100%;
border-radius: 0.4em;
display: flex;
justify-content: center;
align-items: center;
outline: 10px #7d7d7d99;
box-shadow: 3px 5px 15px -4px #999999;
transition: 0.5s all;
&:hover {
background-color: #00935f61;
color: white;
}
&:hover .MuiTypography-root {
color: white;
}
`;
export default function App() {
return (
<ProjectAdd>
<Typography fontSize=".85em" color="#009360">
+ Add
</Typography>
</ProjectAdd>
);
}
https://stackoverflow.com/questions/73389219
复制相似问题