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 trialTaurean Jones
1,482 PointsI am unable to select the em inside the p and color it red
I think I am placing the the descendant selector in the wrong place
em p {color:red;}
<!DOCTYPE html>
<html>
<head>
<title>CSS Selectors</title>
<link rel="stylesheet" href="cc1-main-styles.css" type="text/css" media="screen">
<link rel="stylesheet" href="style.css" type="text/css" media="screen">
em p {color:red;}
</head>
<body class="main-body">
<h1 class="main-h1"><em>Hello</em> World!</h1>
<div>
<p>
<em>Lorem ipsum dolor</em> sit amet, consectetur adipiscing elit. Nunc pulvinar consequat tortor, nec venenatis erat elementum scelerisque. Curabitur sit amet risus nisi. Aenean aliquet euismod augue at viverra. Ut varius arcu in lorem iaculis ullamcorper. Integer eu rutrum quam.
</p>
</div>
</body>
</html>
/* Complete the challenge by writing CSS below */
.main-body {
background-color: lightblue;
}
.main-h1 {
color: darkblue;
}
2 Answers
kheiferfuller
8,635 PointsIn this instance em is a sub element of the p class.
To access an element you can either list them individually or group the elements together(element,element{}) such as:
// div, p { This will make rules for all div elements and all p elements
but to access a sub element(element subelement{}):
// .intro p { This will make rules for all p elements inside .intro elements
So for the problem you'd do:
p em{
color:red;
font-style: italic;
}
Also what they're asking for is for you to utilize the style sheet or an external source for your css. However, in your example you appear to be using an internal css. If you were to use internal css you'd usually needs to be wrapped in a style tag:
<head>
<style>
p em{
color:red;
font-style: italic;
}
</style>
</head>
Ben Chadwick
4,836 PointsHey Taurean.
The code you have wrote is absolutely correct, it just needs to be in your style.css markup !
body {
background:lightblue;
}
h1 {
color: darkblue;
}
p em {
color:red;
}
Hope it helps