Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Miriam Allman
PLUS
Miriam Allman
Courses Plus Student 1,761 Points

Why is my CSS not targeting the rows for colour?

/* Structural Pseudo-classes------------------ */

div:nth-of-type(even) { background: #52bab3; color: white; }

<!DOCTYPE html> <html> <head> <title>Selectors</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href='http://fonts.googleapis.com/css?family=Nunito:400,300' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/style.css"> <style> body { font-family: 'Nunito', sans-serif; color: #616161; padding: 40px 0; } section { margin: auto; width: 50%; } div { border-bottom: 1px dotted; padding: 18px 10px; color: #777;

    }
</style>

</head> <body> <section> <h1>Main Heading</h1> <div>Row 1</div> <div>Row 2</div> <div>Row 3</div> <h1>A new heading</hi> <div>Row 4</div> <div>Row 5</div>
<div>Row 6</div> </section> </body> </html>

Both HTML and CSS are in the same directory yet the colour is not showing up. Can anyone help with this?

2 Answers

<!DOCTYPE html> 
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Selectors</title> 
  <link href='http://fonts.googleapis.com/css?family=Nunito:400,300' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="css/style.css"> 
  <style> 
    body { font-family: 'Nunito', sans-serif; color: #616161; padding: 40px 0; } 
    section { margin: auto; width: 50%; } 
    div { border-bottom: 1px dotted; padding: 18px 10px; color: #777;}
 </style>
</head>
<body>
  <section>
    <h1>Main Heading</h1>
    <div>Row 1</div>
    <div>Row 2</div>
    <div>Row 3</div>
    <h1>A new heading</h1>
    <div>Row 4</div>
    <div>Row 5</div>
    <div>Row 6</div>
  </section>
</body>
</html>

The row text is colored in #777 which is correct because the text is inside div and you set the color to #777 for the text.

What color do expect them to be?

Loek Weijts
Loek Weijts
6,159 Points

If you put put the line in your CSS:

div { border-bottom: 1px dotted; padding: 18px 10px; color: #777; }
div:nth-of-type(even) { background: #52bab3; color: white; }

Its just working very well? Background is a lightgreen with a white text

It's working for me. Where do you put this css rule?

div:nth-of-type(even) { background: #52bab3; color: white; }