繁体   English   中英

对其他样式组件的引用不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM