【发布时间】:2020-11-04 08:23:24
【问题描述】:
我正在尝试让样式化组件与选择最近的 span 元素一起工作
<label>
<span className="">Password</span>
<input type="password" id="passwordInput" />
</label>
span {
position: absolute;
font-size: 14px;
height: 40px;
color: #a2a2a2;
line-height: 40px;
right: 0;
left: 8px;
cursor: auto;
}
input {
height: 40px;
padding-left: 8px;
padding-top: 10px;
padding-bottom: 10px;
width: 100%;
border: 1px solid #dbdbdb;
background-color: #fafafa;
border-radius: 3px;
cursor: auto;
font-size: 16px;
&:focus {
& + span {
background-color: red;
}
outline: #a2a2a2;
border: 1px solid #a2a2a2;
}
}
我不知道该怎么做,这就是我现在正在尝试的方法,但它不起作用。最好我想让它们在不给出跨度、特定类的情况下工作。
【问题讨论】:
-
你不能使用 CSS。您不能选择前面的同级。您可以更改标记以将跨度放在输入元素之后,然后使用 CSS 将它们移动到您想要的位置。
-
这能回答你的问题吗? Is there a "previous sibling" selector?
标签: html css reactjs styled-components