css - 对其他样式组件的引用不起作用
问题描述
为什么在这种情况下${InputBox}:focus & { ... }
不起作用styled-components
?还有其他方法可以使这项工作吗?
export const InputBox = styled.input`
position: absolute;
border: none;
border-bottom: 1px solid black;
background: transparent;
&:focus {
outline: none;
border-bottom: 1px solid blue;
}
export const Placeholder = styled.div`
margin-top: 0px;
${InputBox}:focus & {
margin-top: 50px;
color: white;
}
解决方案
当您InputBox
呈现为 html 元素时,您需要通过元素名称或 className 来覆盖样式。
export const InputBox = styled.input`
position: absolute;
border: none;
border-bottom: 1px solid black;
background: transparent;
&:focus {
outline: none;
border-bottom: 1px solid blue;
}`
export const Placeholder = styled.div`
margin-top: 0px;
input:focus & {
margin-top: 50px;
color: white;
}`
推荐阅读
- c - 如何在 GadgetFS 中指定 HID 报告
- spring - 每个请求模型的事件循环和线程之间的区别
- javascript - 在主线程期间执行的异步任务
- python - 从另一个函数 Python 读取变量
- apache-spark - Spark SQL如何查询Array [Struct]中的结构字段子集?
- react-native - 即使 saga 以 `spawn` 开始,Redux Saga 似乎也会阻止执行
- ios - GetStream iOS native - 如何在第一次初始化后更新客户端令牌
- c++ - 使用 std::make_shared 以 std::array 作为参数初始化 std::shared_ptr
- javascript - 在初始化时使所有过滤器选项“激活” - Angular
- acumatica - 如何在项目报价屏幕上添加字段 PQ000025