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

Elias Sersun Uhalde
Elias Sersun Uhalde
12,131 Points

Classes in media queries

Can I use classes to target elements in media queries?

1 Answer

Yes.

In the below example, I'm targeting the box class and setting it's background to purple for any devices larger than 600px.

.box {
    width: 500px;
    height: 500px;
    background: red;
}

@media (min-width: 600px) {
    .box {
        background: purple;
    }
}

If you're using Sass:

.box {
    width: 500px;
    height: 500px;
    background: red;
    @media (min-width: 600px) {
        background: purple;
    }
}