Media Query
Media query is a CSS technique introduced in CSS3.
It uses the @media rule to include a block of CSS properties only if a certain condition is true.
Media queries enable us to create a responsive website design (RWD) where specific styles are applied to small screens, large screens, and anywhere in between. The media query syntax allows for the creation of rules that can be applied depending on device characteristics.
General Syntax of Media Query
@media (query) {
/* CSS Rules used when query matches */
}
While there are several different items we can query on, the ones used most often for responsive web design are min-width, max-width, min-height and max-height.
Let's have a look at device specific queries:
1. Mobile
There are two different resolution for laptops.
-
- @media only screen
- and (min-device-width : 320px)
- and (max-device-width : 480px)
- { }
Generally, this dimension is recommended for mobile: -
- @media only screen
- and (min-device-width : 360px)
- and (max-device-width : 640px)
- { }
2. Laptop
There are two different resolution for laptops.
-
- @media only screen
- and (min-device-width : 768px)
- and (max-device-width : 1024px)
- { }
-
- @media only screen
- and (min-width: 1030px)
- and (max-width: 1366px)
- { }
Generally, this dimension is recommended for laptop,
3. Desktop - @media only screen
- and (min-width: 1370px)
- and (max-width: 1605px)
- { }
4. iPad -
-
- @media only screen
- and (orientation : landscape)
- and (-webkit-min-device-pixel-ratio: 1)
- and (min-device-width : 768px)
- and (max-device-width : 1007px)
- { }
-
- @media only screen
- and (orientation : portrait)
- and (-webkit-min-device-pixel-ratio: 1)
- and (min-device-width : 768px)
- and (max-device-width : 1007px)
- { }
I have attached sample .css file in this article. Guys, keep exploring. If you have any queries, please feel free to contact me.