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 Responsive Layouts Media Queries Creating Breakpoints

yoav green
yoav green
8,611 Points

left margin, why?

why did he use left margins?

nav li:first-child a {
    margin-left: 0;
  }

  nav li:last-child a {
    margin-right: 0;
  }

(min-width 480px)

3 Answers

Valarie Sherr
Valarie Sherr
1,375 Points

It may be because somewhere else in your code, the left margin was set to something greater than zero for that element. Things that are closer to the bottom have more importance in CSS, so this would override the margin value that you had it set to previously.

yoav green
yoav green
8,611 Points
/******************************
Flexbox Layout
*******************************/

.header, .nav {
  display: flex;
  flex-direction: column;
}

.header {
  justify-content: space-between;
}

.nav {
  flex: 1;
  justify-content: space-around;
}

@media all and (min-width: 640px) {
  .header, .nav {
    flex-direction: row;
  }
}

@media all and (min-width: 1030px) {
  .nav {
    flex: none;
  }
}


/******************************
Additional Styling
*******************************/

body {
  margin: 0;
  font-family: Helvetica;
  background: #5fcf80;
}

.header {
  padding: 20px 0;
  margin: 0 auto;
}

.logo {
  background: transparent url('../img/treehouse-white.svg') center center no-repeat;
  width: 195px;
  background-size: contain;
  text-indent: 100%;
  white-space: nowrap;
  overflow: hidden;
}

.nav {
  list-style: none;
}

.nav li {
  margin: 12px 0 12px 28px;
}

.nav li a {
  text-decoration: none;
  color: #fff;
  font-size: 12px;
  text-transform: uppercase;
}

.nav li a:hover {
  color: rgba(255,255,255,0.7);
}

.nav li:last-child a {
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  transition: 200ms ease-in-out;
  padding: 8px 16px 7px;
}

.nav li:last-child a:hover {
  background: rgba(255,255,255,0.5);
  color: #fff;
}

@media all and (min-width: 1030px) {
  .header {
    width: 1030px;
    min-width: 768px;
  }
}
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Responsive Design</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" href="css/normalize.min.css">
        <link rel="stylesheet" href="css/main.css">
    </head>
    <body>

      <header class="header">
        <h1 class="logo">Logo</h1>
        <ul class="nav">
          <li><a href="#">Features</a></li>
          <li><a href="#">Pricing</a></li>
          <li><a href="#">Sign In</a></li>
          <li><a href="#">Free Trial</a></li>
        </ul>
      </header>

    </body>
</html>
yoav green
yoav green
8,611 Points

still dont get why we needed the margin left.