我有以下 html 结构:
<div class="unit">
<span class="error"></span>
<input type="text" class="textInput"/>
</div>
我仅在验证限制被打破时才添加跨度。
因此,如果验证通过,我将呈现以下 html:
<div class="unit">
<input type="text" class="textInput"/>
</div>
如果 css 具有类 error
的兄弟跨度,是否可以在 css 中为输入绘制红色边框。
最佳答案
你可以试试adjacent sibling选择器
.error + input.textInput
{
border:1px solid red;
}
关于html - 添加样式如果元素有特定的兄弟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31557607/