[英]Reference to other styled component doesn't work
为什么在这种情况下${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;
}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.