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 CSS Layout Techniques Grid Layout Testing our Grid

Gavin Broekema
seal-mask
.a{fill-rule:evenodd;}techdegree
Gavin Broekema
Full Stack JavaScript Techdegree Student 22,443 Points

Selecting descendants that aren't defined in the markup?

I'm confused with this bit of code here...

  .grid-container > [class^="grid-"]:first-child {
    margin-left: 0;
  }
  .grid-container > [class^="grid-"]:last-child {
    float: right;
  }

How are we to select a child of .grid-container when it hasn't been written in the markup? I understand and can picture the container, I just don't understand how we are essentially selecting white-space as a direct "child" of our container.

Mark Pryce
Mark Pryce
8,804 Points

Could you show the markup? might make more sense to me then because the css seems straight forward to me.

Thanks :)

Gavin Broekema
seal-mask
.a{fill-rule:evenodd;}techdegree
Gavin Broekema
Full Stack JavaScript Techdegree Student 22,443 Points
<!DOCTYPE html>
<html>
<head>
    <title>Grid Layout</title>
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/grid.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <header class="main-header">
      <div class="grid-container">
        <h1 class="grid-2 main-logo"><a href="#">Logo</a></h1>
        <ul class="grid-8 main-nav">
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Link 4</a></li>
        </ul>
      </div>
    </header>
    <div class="main-banner hide-mobile">
        <h1>This is the Main Banner Heading</h1>
        <p>Andouille pork chop pancetta drumstick ground round beef ribs swine brisket ham.</p>
    </div>
    <div class="grid-container">
        <div class="grid-8">
            <h2>Primary Content</h2>
            <img class="feat-img" src="http://lorempixel.com/400/300" />
            <p>Bacon ipsum dolor sit amet chicken pork ground round brisket corned beef ball tip shank tail salami filet mignon ham hock pork belly venison shankle. Pig kielbasa drumstick sausage pork chop boudin. Chicken t-bone salami pork chop, beef ribs kevin ham tri-tip beef venison biltong brisket.</p>
            <p>Venison strip steak meatball chicken, brisket prosciutto sirloin. Capicola drumstick brisket tri-tip salami. Chicken beef jerky, tail turkey prosciutto cow ham sirloin boudin tenderloin.</p>
        </div>
        <div class="grid-4">
            <h3>Secondary Content</h3>
            <p>Strip steak tenderloin kevin swine meatloaf capicola, doner beef turducken pancetta corned beef pork loin shoulder.</p>
            <hr>
            <p>Pork filet mignon leberkas, tail swine venison pancetta turkey shoulder brisket chalkers likes hamburgers.</p>
            <hr>
            <p>Meatball pastrami shoulder, brisket ribeye spare ribs turkey tongue strip steak t-bone.</p>
        </div>
    </div>
    <footer class="main-footer">
        <p>&copy;2014 Example Layout</p>
    </footer>
</body>
</html>

1 Answer

Steven Parker
Steven Parker
231,275 Points

Your markup already has all the elements referenced by these CSS selectors. I see two elements (div) with class grid-container. They both contain child elements with class names beginning with grid-.

Your first selector will target the first child of both groups, and the second selector will target the last child in both groups.

Mark Pryce
Mark Pryce
8,804 Points

But.. but.. I was in the shower, xD good answer Steven.