CSS2 allows you to specify stylesheet for specific media type such as screen or print.
Now CSS3 makes it even more efficient by adding media queries. You can add expressions to media type to check for certain conditions and apply different stylesheets.
For example, it's been common practice for years to use a separate style sheet for printing web pages by specifying media="print" . Media queries take this idea to the next level by allowing designers to target styles based on a number of device properties, such as screen width, orientation, and so on.
a)use in css file
@media screen and (max-width: 500px) { .className { background: #FFFFFF; } }
b)use saparate css file for the devices whose width within 500px.
<link rel="stylesheet" media="screen and (max-width: 500px)" href="small.css" />
@media screen and (min-width: 500px) { .className { background: #FFFFFF; } }
b)use saparate css file for the devices whose width within 500px.
<link rel="stylesheet" media="screen and (min-width: 500px)" href="small.css" />
You can combine multiple media queries. The following code will apply if the viewing area is between 500px and 800px.
@media screen and (min-width: 500px) and (max-width: 800px) { .className { background: #FFFFFF; } }
This is the most important and usefull things.Because the different device has different width.So we can use different css files for different device using the Device Width property.
@media screen and (max-device-width: 600px) { .className { background: #FFFFFF; } }
@media (device-height: 568px) and (-webkit-min-device-pixel-ratio: 2) {
/* iPhone 5 or iPod Touch 5th generation */
}
<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css" />
<link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css" />