Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Selectors Selectors - Beyond the Basics Combinators Challenge

Shahar Golan
Shahar Golan
819 Points

margin-top

.h2 + p { margin-top: 5em; } in the test its I am receiving a message that it's not good,

style.css
/* Complete the challenge by writing CSS below */

.main-nav > li {

  display:inline-block; 
  margin-left: 20px;
}

.h2 + p {
  margin-top: 5em;
}
index.html
<!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="base.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <header class="main-header">
    <h1>My Blog</h1>
    <ul class="main-nav">
      <li><a href="#">About Me</a></li>
      <li><a href="#">My Work</a></li>
      <li><a href="#">Get In Touch</a></li>
    </ul>
  </header>
    <div class="main">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut et feugiat libero. Cras ut fermentum nisi. Nullam mattis, ipsum commodo laoreet volutpat, augue eros ornare lorem, eu interdum leo massa a nibh.</p>
        <p>In vel semper lorem. Pellentesque in quam pulvinar, fringilla justo ac, accumsan ante. Etiam in malesuada lacus.</p>

        <div class="post">
            <h2>Post Heading</h2>
            <p>Nulla eu vestibulum mauris. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Integer blandit ex velit, vitae consequat quam viverra at... <a href="#">read more &raquo;</a></p>
        </div>
        <div class="post">
            <h2>Post Heading</h2>
            <p>Aliquam cursus tempor molestie. Phasellus nec mattis elit. Sed fringilla laoreet magna, sodales vulputate leo auctor eu. Cras scelerisque laoreet faucibus. Proin cursus, metus... <a href="#">read more &raquo;</a></p>
        </div>
    </div>
</body>
</html>

4 Answers

John O'Connor
seal-mask
.a{fill-rule:evenodd;}techdegree
John O'Connor
Front End Web Development Techdegree Student 14,113 Points

Tim is correct.

If you are targeting a simple selector such as h2 to increase it's margin you will call it in your css like so:

h2 { margin-top: 5em; }

You will only want to use a period in front of a css call out when it is a class. So if you wanted to only specifically call out that h2 in your html it could look something like this: <h2 class="header-margin">Post Margin</h2> --- You would then call this h2 in your css with the class name which in css would look like:

.header-margin{ margin-top: 5em; }

Now since you want to give that styling to all the <h2> tags in your html and also the <p> you would use a solution like this:

h2, p { margin-top: 5em; }

To give the same styling to multiple selectors you separate using a comma and not a + sign. Hope this helps.

Tim Betz
Tim Betz
15,146 Points

You need to use the normal h2 selector. What you are doing is, you get the class h2 (.h2) and all paragraphs (p). Your selector for the margin should look like h2, p not .h2, p

Shahar Golan
Shahar Golan
819 Points

I got a message: Are you setting the correct 'margin-top' value?

Shahar Golan
Shahar Golan
819 Points

Thank you for all of your answers the question on the test was: It looks like we need to decrease the space between h2 elements and the paragraph that immediately follows. Create a new selector that targets p elements that are adjacent siblings of an h2. Then, set the top margin to .5em. And I wrote: h2 + p {margin-top: 5em} I got a message that is not correct :"Are you setting the correct 'margin-top' value?"

Thanks