0
I have the following code:
.line-item:hover td {
background-color: yellow;
}
.item-text:focus + .line-item td {
background-color: red !important;
}
<table border="1">
<tr class="line-item">
<td>L1C1</td>
<td>L1C2</td>
<td><input class="item-text" type="text" /></td>
</tr>
<tr class="line-item">
<td>L2C1</td>
<td>L2C2</td>
<td><input class="item-text" type="text" /></td>
</tr>
</table>
The goal is to leave the line in which the text
was focused red.
When passing the mouse over any element realize that the line is yellow. When clicking on the text I would like the line to be red.
Using Javascript would look like this:
$(".item-text").focusin(function(){
$(this).closest(".line-item").css("background-color", "red");
}).focusout(function(){
$(this).closest(".line-item").css("background-color", "transparent");
});
.line-item:hover td {
background-color: yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table border="1">
<tr class="line-item">
<td>L1C1</td>
<td>L1C2</td>
<td><input class="item-text" type="text" /></td>
</tr>
<tr class="line-item">
<td>L2C1</td>
<td>L2C2</td>
<td><input class="item-text" type="text" /></td>
</tr>
</table>
But I would like to do only with CSS, it is possible?
can use javascript or it’s just css?
– zwitterion
@zwitterion css even, if possible.
– Jedaias Rodrigues
@Jedaiasrodrigues You can change the color of the input, but select an element by "logic" (ie if this element is
focus
THE RELATIVE GETSred
) is complicated javascript free because CSS and logic do not go hand in hand; fiddle here is the selector for theinput
then with javascript you can add a classonfocus
to the relative of the clicked element– MoshMage
@Jedaiasrodrigues edited the answer again, take a look
– João Victor Gomes Moreira
@Change your comment into an answer I already accept, and if possible also put an example of alternative structure in which it works will be perfect!
– Jedaias Rodrigues
Although I’m studying these examples to get a css solution. link1 Link2
– Jedaias Rodrigues
@Jedaiasrodrigues solved the problem? If yes, mark the answer as a solution, thank you friend
– João Victor Gomes Moreira