I'm having difficulty with CSS selectors and I hope someone can perhaps help me out here.
I have some HTML that looks like so:
<table class=myTable> <tr> <td>this is the td of interest</td> </tr> <tr> <td> <table> <tr><td>I don't want this td!</td></tr> </table> </td> </tr> </table>
I am trying to apply a background image to the FIRST td of the FIRST tr. So I tried the following:
table.myTable tr:first-child td:first-child { background-image: url(someUrl.gif); }
But this is also finding the first td of the first tr of the nested table. I've tried different combinations with > and +, but no luck. Anyone have any ideas?
Note: I'm aiming for a solution that is compatible with IE7+.
The ::first-line selector is used to add a style to the first line of the specified selector. Note: The following properties can be used with ::first-line: font properties.
You could also have table > thead > tr and then table > tbody > tr. So you might need to specify whether you want the first row from the thead or the tbody. find('tr:first') will select the tr in the thead. – Jeff S.
To freeze the row/column we can use a simple HTML table and CSS. HTML: In HTML we can define the header row by <th> tag or we can use <td> tag also. Below example is using the <th> tag. We also put the table in DIV element to see the horizontal and vertical scrollbar by setting the overflow property of the DIV element.
The selector you need is
table.myTable > tbody > tr:first-child > td:first-child
There is an implicit TBODY element in there, even though you don't have it in the code.
table.myTable > tr:first-child > td:first-child
The > means the tr that is a direct child of table
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