How to find the previous sibling of HTML tag using CSS only:
<div class="form-group">
<label for="userID">User ID</label>
<input id="userID" type="text" class="form-control" placeholder="Enter User ID" tabindex="1"/>
</div>
How to find the previous sibling of HTML tag using CSS only:
<div class="form-group">
<label for="userID">User ID</label>
<input id="userID" type="text" class="form-control" placeholder="Enter User ID" tabindex="1"/>
</div>
I don't think you can, you can however find the next sibling. You didn't even write from which element you want to search and what is the target but I assume you want to go from the <label>
to <input>
..?
Then just reverse the order they come in html and you can put back the order using css.
html:
<div class="form-group">
<input id="userID" type="text" class="form-control" placeholder="Enter User ID" tabindex="1"/>
<label for="userID">User ID</label>
</div>
css
.form-group {
display: flex;
flex-direction: column; // if they should be one one line each
}
[for="userID"] {
order: -1;
}