reactjs - 样式化的组件不应用样式
问题描述
我有这 2 个样式的组件
export const Icon = styled.svg`
width: 8px;
height: 8px;
background: black;
`
export const Dots = styled.div`
border: 2px solid green !imporant;
height: 30px;
background: white;
width: 16px;
height: 16px;
border: solid 1px #d2d2d2;
border-radius: 20px;
top: 25px;
position: relative;
${Icon}: hover {
background:black;
}
}
`
我想Icon
在这个 div 的悬停上显示,但我不明白为什么它不起作用,请问有什么建议吗?
解决方案
您的代码没有问题,除非在悬停时您不会更改默认值的颜色black
const Icon = styled.div`
width: 100px;
height: 100px;
background: black;
`;
export const Dots = styled.div`
${Icon}:hover {
background: red;
}
`;
export default function App() {
return (
<Dots>
<Icon />
</Dots>
);
}
推荐阅读
- presto - 在 Presto 的基于文件的系统访问控制中设置表规则时出现 AccessDeniedException
- c# - 无法将 lambda 作为表达式隐式传递
- javascript - 使用 JSON.stringify() 和 json_decode() 将数据从 javascript 发送到 php
- php - OCI8 不显示结果
- c++ - C++ SFINAE 构造函数也接受派生类
- java - 未找到 Bash 命令并且方法有问题
- typescript - 如何使用express在回调函数之间传递值?
- javascript - 使用 req,res 参数调用函数
- c - 使用 malloc 函数后 printf 下一行中的随机字母
- php - 如何根据关键字输入搜索 CSV 文件并返回多个条目