【发布时间】:2021-05-14 09:54:59
【问题描述】:
当输入聚焦时,我试图更改输入中的小 svg 颜色,但我不知道如何正确定位它。在 devtools 中,我可以直接更改 label 或 svg 的颜色,它们都可以工作。
<form action="" className="search-bar input-wrapper" onSubmit={(e) => handleSubmit(e)}>
<input
type="text"
className="input"
id="search-bar-input"
placeholder="Search..."
value={searchbar}
onChange={(e) => handleChange(e)}
onKeyDown={(e) => handleKeyDown(e)}
/>
<label id="input-label" htmlFor="search-bar-input">
<VscSearch id="input-icon" className="input-icon" />
</label>
</form>
我试过但没用的东西:
#search-bar-input:focus ~ #input {
color: red;
}
#search-bar-input:focus + #input {
color: red;
}
#search-bar-input:focus ~ #input-icon {
color: blue;
}
#search-bar-input:focus + #input-icon {
color: blue;
}
.search-bar {
&:focus {
#input-label {
color: yellow;
}
#input-label {
svg {
color: orange;
}
}
#input-icon {
color: green;
}
}
}
我可以用 sass 或 CSS 来写,没关系。
【问题讨论】:
标签: html css user-interface sass css-selectors