Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

CSS: I want to target each child separately in a container

CSS: I want to target each child separately in a container

Problem

I want to assign seperate colors to each . One solution is to use classes, but I don't want to crowd the HTML if a simple CSS selector solution exists.

HTML:

Item 1
  Item 2
  Item 3
  Item 4

CSS:

/* item #1 */
{color: red}

/* item #2 */
{color: blue}

/* item #3 */
{color: green}
Problem courtesy of: Don P

Solution

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

Solution courtesy of: j08691

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

CSS: I want to target each child separately in a container

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×