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 One Solution

Cody Santek
Cody Santek
4,625 Points

Is it still recommended to not repeat youself (DRY) with media queries?

I've noticed I went further than Anwar did in this lesson, trying my best to not repeat myself but in his solution he did not. Instead of writing float: left; twice in both media queries I combined them into a 3rd media query. Is it recommended to do this?

@media print {
  nav li {
    display: none;
  }
  figure {
    width: 50%;
    margin-right: 1rem;
  }
}

@media screen and (min-width: 768px) {
  figure {
    width: 360px;
    margin: 0 1rem 2rem 0;
  }
  nav li {
    display: inline-block;
    margin-left: 1.5rem;
  }
  nav li:first-child {
    margin-left: 0;
  }
  .no-wrap {
    clear: both;

  }
}

@media print, screen and (min-width: 768px) {
  figure {
    float: left;
  }
}

1 Answer

Steven Parker
Steven Parker
229,608 Points

The general recommendation for "DRY" code is partly about keeping the code compact. Where it takes more code to avoid repeating something, it's probably a good place to allow an exception.

Cody Santek
Cody Santek
4,625 Points

Okay thank you, ill keep that in mind.