My HTML:
<tr><td>Text</td><td><input type="text" value=""></td></tr>
My CSS:
input:focus tr{ background-color:#fff;}
I want to highlight the row in white when I'm writing text in the input field. I know "tr" is before "input", but is this possible to do in any way?
Thanks a bunch
The background color of the table is given by the bgcolor="color" attribute. When applied to the <table> tag, the color fills the background. Cell background colors are set by applying the bgcolor attribute to a <tr> tag (to color the row) or to a <td> tag (to color the cell).
HTML | <tr> bgcolor Attribute color_name: It sets the background color by using the color name. For example “red”.
To change the background color of a single cell, use the attribute bgcolor="color" inside the <td> tag. To add a tiled background image to a single cell, use the attribute background="URL" inside the <td> tag.
The HTML <table> bgcolor Attribute is use to specify the background color of a table. Attribute Values: color_name: It sets the text color by using the color name. For example “red”.
No, sadly. See: Complex CSS selector for parent of active child
Here's how you could do it, though: http://jsfiddle.net/minitech/udzcp/
Using JQuery, it is very possible. Observe:
HTML
<table border="1" cellpadding="20">
<tr>
<td>Text</td>
<td height="50" width="100" id="somename"><input type="text" value="" id="mirza"></td>
</tr>
<tr><td> </td><td> </td></tr>
<tr><td>a </td><td>1 </td></tr>
<tr><td>a </td><td>1 </td></tr>
<tr><td>a </td><td>1 </td></tr>
<tr><td>a </td><td>1 </td></tr>
<tr><td>a </td><td>1 </td></tr>
</table>
CSS
.highlightedRow { background-color: orange; }
Jquery
$('input').focus(function() {
$(this).parent().parent().addClass('highlightedRow');
});
$('input').blur(function() {
$(this).parent().parent().removeClass('highlightedRow');
});
Sadly, there's no way to style the parent element with CSS, so you'll have to use javascript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With