CSS & CSS3 Media Query – An Introduction

Media queries are simple filters that can be applied to CSS styles. They make it easy to change styles based on the characteristics of the device rendering the content, including the display type, width, height, orientation and even resolution.

CSS Print Media Query – CSS style for print

<link rel="stylesheet" href="print.css" media="print"

Different ways to use media query in css?

CSS3 Media queries allow you to target CSS rules based on – for instance – screen size, device-orientation or display-density. This means you can use CSS Media Queries to tweak a CSS for an iPad, printer or create a responsive site.

The media query syntax allows for the creation of rules that can be applied depending on device characteristics.

@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-widthmax-widthmin-height and max-height.

attributeResult
min-widthRules applied for any browser width over the value defined in the query.
max-widthRules applied for any browser width below the value defined in the query.
min-heightRules applied for any browser height over the value defined in the query.
max-heightRules applied for any browser height below the value defined in the query.
orientation=portraitRules applied for any browser where the height is greater than or equal to the width.
orientation=landscapeRules for any browser where the width is greater than the height.

media_queries

  <link rel="stylesheet" media="(max-width: 640px)" href="max-640px.css">
    <link rel="stylesheet" media="(min-width: 640px)" href="min-640px.css">
    <link rel="stylesheet" media="(orientation: portrait)" href="portrait.css">
    <link rel="stylesheet" media="(orientation: landscape)" href="landscape.css">
    <style>
      @media (min-width: 500px) and (max-width: 600px) {
        h1 {
          color: fuchsia;
        }

        .desc:after {
          content:" In fact, it's between 500px and 600px wide.";
        }
      }
    </style>

Below is an overview of most of the CSS3 media queries. You can find what queries your browser support and better support your devices.

#Query
1YES@media all
2YES@media screen
3NO@media handheld
4NO@media aural
5NO@media braille
6NO@media embossed
7NO@media projection
8NO@media tty
9NO@media tv
10NO@media print
11NO@media 3d-glasses
12YES@media all and (orientation:landscape)
13NO@media all and (orientation:portrait)
14YES@media screen and (min-width : 320px)
15YES@media screen and (min-width : 480px)
16YES@media screen and (min-width : 1224px)
17NO@media screen and (min-width : 1824px)
18YES@media screen and (min-width : 29em)
19YES@media screen and (min-width : 35em)
20NO@media all and (device-aspect-ratio: 2/3)
21NO@media all and (device-aspect-ratio: 4/3)
22NO@media all and (device-aspect-ratio: 3/4)
23NO@media all and (device-aspect-ratio: 3/5)
24NO@media all and (device-aspect-ratio: 5/3)
25NO@media all and (device-aspect-ratio: 8/5)
26NO@media all and (device-aspect-ratio: 15/9)
27NO@media all and (device-aspect-ratio: 9/16)
28NO@media all and (device-aspect-ratio: 256/135)
29NO@media all and (-webkit-device-pixel-ratio: .75)
30YES@media all and (-webkit-device-pixel-ratio: 1)
31NO@media screen and (-o-device-pixel-ratio: 1/1)
32YES@media screen and (resolution: 96dpi)
33NO@media screen and (-webkit-min-device-pixel-ratio: 1.3)
34YES@media screen and (-webkit-device-pixel-ratio: 1.5), screen and (resolution: 96dpi)
35NO@media all and (-webkit-device-pixel-ratio: 1.5)
36NO@media screen and (-o-device-pixel-ratio: 3/2)
37NO@media screen and (resolution: 144dpi)
38NO@media screen and (-webkit-device-pixel-ratio: 1.5), screen and (resolution: 144dpi)
39NO@media all and (-webkit-min-device-pixel-ratio: 2)
40NO@media screen and (min-resolution: 192dpi)
41NO@media screen and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait)
42NO@media screen and (device-width: 768px) and (device-height: 1024px) and (orientation:landscape)
43NO@media screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-min-device-pixel-ratio: 1)
44NO@media screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-min-device-pixel-ratio: 

 Table Reference – http://cssmediaqueries.com/overview.html

 

 

Leave a Reply