I want to assign seperate colors to each <td>
. One solution is to use classes, but I don't want to crowd the HTML if a simple CSS selector solution exists.
HTML:
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
CSS:
/* item #1 */
{color: red}
/* item #2 */
{color: blue}
/* item #3 */
{color: green}
Use CSS's nth-child
selector:
td:nth-child(1) {
color:blue;
}
td:nth-child(2) {
color:red;
}
td:nth-child(3) {
color:brown;
}
td:nth-child(4) {
color:green;
}
jsFiddle example
You can use the nth-child
selector to specify a specific element (counting from 1): td:nth-child(1) { color: red; }
http://jsfiddle.net/ayTmy/
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