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 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
218,596 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.