Media query consists of a media type and atleast one expression that limits the stylesheet scope by using media features like width, height etc.
With @media query , we can write different css code for different media types. Like, we can write different css code for different media type like for Screen and Printer.
The simplest way to use media queries is to have a block of CSS code in the same stylesheet file. So all the CSS that is specific to mobile phones, would be defined in the following block:
But is it difficult to manage code in a single style sheet for several devices. So, we can have different style sheet for specific screen sizes.
Another way to add css is @import method -
But it is good to use first two method, avoid @import method (not recommended).
Lets see some media query examples -
In above example, example.css will be applied when width will be lower than 800px;
Above, block wiull be hidden when width will be smaller than 600px.
Change the background color if screen is smaller than 300px in width ;
Comments
Post a Comment