【发布时间】:2021-06-11 22:44:45
【问题描述】:
import styled from "styled-components";
const Styles = styled.div`
.App {
&__input {
width: 200px;
background-color: orangered;
&:focus {
background-color: greenyellow;
}
}
&__button {
background-color: grey;
}
/* this works */
&__input:focus + .App__button {
background-color: greenyellow;
}
/* this doesn't */
&__input:focus + &__button {
background-color: greenyellow;
}
}
`;
export default function App() {
return (
<Styles>
<div className="App">
<input className="App__input" />
<button className="App__button">click</button>
</div>
</Styles>
);
}
正如您在代码中看到的,我希望 & 引用 .App,因为它在其他地方以及 node_sass 中都可以使用。
这是样式组件中的错误还是我在这里遗漏了什么?
这里是 codesandbox link 来复制问题。
【问题讨论】:
标签: css sass styled-components