IMG-LOGO

Media Queries

andy - 28 Jun, 2014 4650 Views 0 Comment

Media queries are simple conditions used to targetting different devices for tables, phones or desktop computers. As each device may have different view size, media queries become so handy to use to display the content dimension correctly.

Browser support for Media Queries

Media queries are supported by the following browsers: IE9+, Chrome 4+, Firefox 3.5+, Opera 9.5+, Safari 4+, Android 2.1+, iOS Safari 3.2+

How it works?

It is pretty simple, you just need to specify different dimension size wrap inside a dimension code block. It is like an if condition code block, where you just need to define the minimum width or maximum width or could be combination of both dimension together.

/* Smaller than standard 960 (devices and browsers) */
@media only screen and (max-width: 959px) {
   /*** ENTER YOUR CSS CODE IN HERE ***/
}

/* Tablet Portrait size to standard 960 (devices and browsers) */
@media only screen and (min-width: 768px) and (max-width: 959px) {
   /*** ENTER YOUR CSS CODE IN HERE ***/
}

/* All Mobile Sizes (devices and browser) */
@media only screen and (max-width: 767px) {
   /*** ENTER YOUR CSS CODE IN HERE ***/
}

/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */
@media only screen and (min-width: 480px) and (max-width: 767px) {
   /*** ENTER YOUR CSS CODE IN HERE ***/
}

/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */
@media only screen and (max-width: 479px) {
   /*** ENTER YOUR CSS CODE IN HERE ***/
}

If you prefer to separate the css into an external file, you can use the following sample code.

<link type="text/css" rel="stylesheet" href="mobile.css" media="only screen and (max-width: 320px)"/>

<link type="text/css" rel="stylesheet" href="tablet.css" media="only screen and (min-width: 769px) and (max-width: 960px)"/>

If you prefer to import the css directly from a css file, you can use the following sample code.

@import url(mobile.css) only screen and (max-width: 320px);
@import url(tablet.css) only screen and (min-width: 769px) and (max-width: 960px);

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Blogs

How to draw a circle in CSS?

In this article, we are going to learn how to draw a circle in CSS. Firstly what needs to do is to create a CSS class called circle.

Related Tutorials

CSS3 Border Radius

With new CSS3 border radius style you can easily create rounded corners for an image or html tag object Back in old days when we want to create a rounded border around an image or object we usually create 4 ...

CSS3 Multiple Column

Learn how to use multiple column property in CSS3 To create multiple columns in CSS3 is now so handy you just need to include a css built in keyword column count to do the job for you No more table ...

CSS3 Opacity

Learn how to use opacity property in CSS3. So what is actually opacity? CSS3 Opacity defines a transparency level of an element. The property value of opacity is range from 0 to 1.

CSS3 Box Sizing

Learn how to use box sizing property in CSS3 As you know many browsers treat margin and padding differently When you combine with width or height of an element box you find out that the final dimension is completely different ...

Advanced Selectors

Learn how to use advanced selectors in CSS3. By using the built in pseudo-class, performing a selector in CSS3 is so much easy.