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.

kabir k
Courses Plus Student 18,036 PointsWhy the difference between @media screen and () {} and @media () {} ?
In the "How to Make a Website" we were taught to write media queries for the Portfolio website, like this:
@media screen and () {}
while in the "CSS Basics" for the Lake Tahoe webiste, like this:
@media () {}
Why the difference between the two?
1 Answer

Greg Kaleka
39,019 PointsHi Kabir,
@media
can also be used for print interfaces, so @media screen
is simply specifying that these rules are to be implemented when displaying on a screen, but not when printing. @media
by itself is more broad, and would apply to print.
There are probably other media that can be targeted, but screen and print are the two I know about.
Best,
-Greg
kabir k
Courses Plus Student 18,036 Pointskabir k
Courses Plus Student 18,036 PointsThanks, Greg. So why didn't we use @media for the Portflio website then?
Also, Nick wrote the media queries as:
@media screen and () {} (with the "and" operator)
while Guil wrote them as:
@media () {} (without the "and" operator)
Is the "and" operator not necessary in the second case?
Greg Kaleka
39,019 PointsGreg Kaleka
39,019 PointsSometimes you want to target just screens, other times you want to target everything. It depends on the project.
Nick needed to use "and" because of the "screen" that comes before it. You read a media query like this:
@media screen and (max-width: 900px) {} "For media that is a screen and with a max width of 900px, do this stuff"
@media (max-width: 900px) {} "For media that has a max-width of 900px, do this stuff"
So just like in plain English, there's no need for and in the second media query. Make sense?
kabir k
Courses Plus Student 18,036 Pointskabir k
Courses Plus Student 18,036 PointsOk, thanks.