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

Challenge Task 1 of 3 Advanced Selectors

I can't figure out how to target the 'img' element inside the media query. Can someone help guide me through this?

3 Answers

You can target an img element inside a media query like this.

@media screen and (max-width: 300px) {
    img {
       border: 2px solid tomato;
    }
}

Media queries basically consistent of the @media rule, a media type, and constraints to select the size or positioning of the device you are targeting. To apply code using a media rule, you simply write all of the css you want to apply to the rule inside of the @media statement's curly braces. If you are looking to select all images, you would simply target them using the img tag, like so:

@media screen and (max-width: 600px) {
img {
width: 100px;
}
}

The numbers I used are arbitrary, but that is the basic syntax. Just make sure that all the css you write for the media query falls inside of the media query curly braces. Then it's just normal css from there.

Appreciate the speedy response! Thanks for the examples and explanation of the theory behind it