I have a snippet that I based on the Base Example, targeting previous sibling with the use of flexbox. It is working nicely with li elements, but as soon as I try to do it with label and input it stops working.
Unfortunately I am relying on a code that puts the label first and input second making it so far impossible to target and manipulate on input:focus
.
Is there any chance that I can get it to work from CSS(I am using Sass so that is an option)?
The base example is from a similar, but general question querying targeting previous sibling rather then the label+input:focus pair.
Base Example
ul {
display: flex;
}
li:hover + li {
background-color: red;
}
li:last-child {
order: -1;
}
/* non-essential decorative styles */
li {
height: 200px;
width: 200px;
background-color: aqua;
margin: 5px;
list-style-type: none;
cursor: pointer;
}
<ul>
<li>B</li>
<li>A</li>
</ul>
Example I'm trying to get to work
div{
display: flex
}
input:focus + label{
color:red;
}
label{
order: 1;
}
<div>
<label for="NAME">Name</label>
<input type="text">
</div>
<div>
<label for="EMAIL">Email</label>
<input type="email">
</div>