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

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;
    }
}