Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如果元素具有特定同级,则添加样式_Html_Css - Fatal编程技术网

Html 如果元素具有特定同级,则添加样式

Html 如果元素具有特定同级,则添加样式,html,css,Html,Css,我有以下html结构: <div class="unit"> <span class="error"></span> <input type="text" class="textInput"/> </div> 仅当验证限制被打破时,我才添加跨度 因此,如果验证通过,我将呈现以下html: <div class="unit"> <input type="text" class="te

我有以下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中有类
错误的同级span,有没有办法在css中为输入绘制红色边框

.unit span.error + input.textInput{border:1px solid red;}

你可以试试选择器


考虑以下代码:

.error + input.textInput {
    border: 1px solid red;
}

这将选择前面紧跟着.error节点的所有.textInput节点。

对不起,我指的是边框,不是轮廓。
.error + input.textInput 
{
   border:1px solid red;
}
.error + input.textInput {
    border: 1px solid red;
}