{"id":541,"date":"2010-08-18T10:45:39","date_gmt":"2010-08-18T15:45:39","guid":{"rendered":"https:\/\/webdesignerwall.com\/tutorials\/css3-media-queries\/"},"modified":"2012-05-18T16:43:39","modified_gmt":"2012-05-18T21:43:39","slug":"css3-media-queries","status":"publish","type":"post","link":"https:\/\/webdesignerwall.com\/tutorials\/css3-media-queries","title":{"rendered":"CSS3 Media Queries"},"content":{"rendered":"<p><big>CSS2 allows you to specify stylesheet for specific media type such as screen or print<a href=\"http:\/\/twitter.com\/themify\"><\/a>. 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, you can have one stylesheet for large displays and a different stylesheet specifically for mobile devices. It is quite powerful because it allows you to tailor to different resolutions and devices without changing the content. Continue on this post to read the tutorial and see some websites that make good use of media queries.<\/big><!--more --><\/p>\n<h3>CSS3 Media Queries <small>(<a href=\"https:\/\/webdesignerwall.com\/demo\/media-queries\/\">demo<\/a>)<\/small><\/h3>\n<p>Check my <a href=\"https:\/\/webdesignerwall.com\/demo\/media-queries\/\">demo<\/a> and resize your browser window to see it in action.<\/p>\n<h4>Max Width<\/h4>\n<p>The following CSS will apply if the viewing area is smaller than 600px.<\/p>\n<pre><code>@media screen and (max-width: 600px) {\r\n  .class {\r\n    background: #ccc;\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>If you want to link to a separate stylesheet, put the following line of code in between the &lt;head&gt; tag.<\/p>\n<pre><code>&lt;link rel=&quot;stylesheet&quot; media=&quot;screen and (max-width: 600px)&quot; href=&quot;small.css&quot; \/&gt;\r\n<\/code><\/pre>\n<h4>Min Width<\/h4>\n<p>The following CSS will apply if the viewing area is greater than 900px.<\/p>\n<pre><code>@media screen and (min-width: 900px) {\r\n  .class {\r\n    background: #666;\r\n  }\r\n}\r\n<\/code><\/pre>\n<h4>Multiple Media Queries<\/h4>\n<p>You can  combine multiple media queries. The following code will apply if the viewing area is between 600px and 900px.<\/p>\n<pre><code>@media screen and (min-width: 600px) and (max-width: 900px) {\r\n  .class {\r\n    background: #333;\r\n  }\r\n}\r\n<\/code><\/pre>\n<h4>Device Width<\/h4>\n<p>The following code will apply if the max-device-width is 480px (eg. iPhone display). Note: max-device-width means the actual resolution of the device and max-width means the viewing area resolution.<\/p>\n<pre><code>@media screen and (max-device-width: 480px) {\r\n  .class {\r\n    background: #000;\r\n  }\r\n}\r\n<\/code><\/pre>\n<h4>For iPhone 4<\/h4>\n<p>The following stylesheet is specifically for iPhone 4 <em>(credits: <a href=\"http:\/\/thomasmaier.me\/2010\/06\/css-for-iphone-4-retina-display\/\">Thomas Maier<\/a>)<\/em>.<\/p>\n<pre><code>&lt;link rel=&quot;stylesheet&quot; media=&quot;only screen and (-webkit-min-device-pixel-ratio: 2)&quot; type=&quot;text\/css&quot; href=&quot;iphone4.css&quot; \/&gt;<\/code><\/pre>\n<h4>For iPad<\/h4>\n<p>You can also use media query to detect orientation (portrait or landscapse)  on the iPad <em>(credits: <a href=\"http:\/\/www.cloudfour.com\/ipad-css\/\">Cloud Four<\/a>)<\/em>.<\/p>\n<pre><code>&lt;link rel=&quot;stylesheet&quot; media=&quot;all and (orientation:portrait)&quot; href=&quot;portrait.css&quot;&gt; \r\n&lt;link rel=&quot;stylesheet&quot; media=&quot;all and (orientation:landscape)&quot; href=&quot;landscape.css&quot;&gt;<\/code><\/pre>\n<h3>Media Queries for Internet Explorer<\/h3>\n<p>Unfortunately, media query is not supported in Internet Explorer 8 or older. You can use Javascript to hack around. Below are some solutions:<\/p>\n<ul>\n<li><a href=\"http:\/\/css-tricks.com\/resolution-specific-stylesheets\/\">CSS Tricks &#8211; using jQuery to detect browser size<\/a><\/li>\n<li><a href=\"http:\/\/www.themaninblue.com\/experiment\/ResolutionLayout\/\">The Man in Blue &#8211; using Javascript<\/a> (this article is written 6 years ago)<\/li>\n<li><a href=\"http:\/\/plugins.jquery.com\/project\/MediaQueries\">jQuery Media Queries Plugin<\/a><\/li>\n<\/ul>\n<h3>Sample Sites<\/h3>\n<p>You need to view the following sites with a browser that supports media queries such as Firefox, Chrome, and Safari. Go to each site and see how the layout responds base on the size of your browser winow.<\/p>\n<h4><a href=\"http:\/\/hicksdesign.co.uk\">Hicksdesign<\/a><\/h4>\n<ul>\n<li><strong>Large size:<\/strong> 3 columns sidebar<\/li>\n<li><strong>Smaller:<\/strong> 2 columns sidebar (the middle column drops to the left column)<\/li>\n<li><strong>Even smaller:<\/strong> 1 column sidebar (the right column shift up below the logo)<\/li>\n<li><strong>Smallest:<\/strong> no sidebar (logo &amp; right column shift up and the other sidebar columns move below)<\/li>\n<\/ul>\n<p class=\"image\"><img decoding=\"async\" src=\"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/hicksdesign.jpg\" alt=\"screen capture\" \/><\/p>\n<h4><a href=\"http:\/\/colly.com\">Colly<\/a><\/h4>\n<p>The layout switches between one column, 2 columns, and 4 columns depend on the viewing area of your browser.<\/p>\n<p class=\"image\"><img decoding=\"async\" src=\"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/colly.jpg\" alt=\"screen capture\" \/><\/p>\n<h4><a href=\"http:\/\/www.alistapart.com\/d\/responsive-web-design\/ex\/ex-site-FINAL.html\">A List Apart<\/a><\/h4>\n<ul>\n<li><strong>Large size:<\/strong> navigation at the top, 1 row of pictures<\/li>\n<li><strong>Medium size:<\/strong> navigation on the left side, 3 columns of pictures<\/li>\n<li><strong>Small size:<\/strong> navigation at the top, no background image on logo, 3 columns of pictures<\/li>\n<\/ul>\n<p class=\"image\"><img decoding=\"async\" src=\"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/alistapart.jpg\" alt=\"screen capture\" \/><\/p>\n<h4><a href=\"http:\/\/teegallery.com\">Tee Gallery<\/a><\/h4>\n<p>This one is very similar to previous example Colly, but the difference is the images of TeeGallery resize as the layout stretchs. The trick here is use relative percentage value instead of fixed pixel (ie. width=100%).<\/p>\n<p class=\"image\"><img decoding=\"async\" src=\"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/teegallery.jpg\" alt=\"screen capture\" \/><\/p>\n<h3>Conclusion<\/h3>\n<p>Keep in mind: having an optimized stylesheet for mobile devices doesn&#8217;t mean your site is optimized for mobile. To be truly optimized for mobile devices, your images and markups need to cut on the load size as well. Media queries are meant for design presentation, not optimization.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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, you can have one stylesheet for large displays and a different [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[31,1],"tags":[21,40],"class_list":["post-541","post","type-post","status-publish","format-standard","hentry","category-featured","category-tutorials","tag-css","tag-responsive-design"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CSS3 Media Queries - Web Designer Wall<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CSS3 Media Queries - Web Designer Wall\" \/>\n<meta property=\"og:description\" content=\"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, you can have one stylesheet for large displays and a different [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries\" \/>\n<meta property=\"og:site_name\" content=\"Web Designer Wall\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webdesignerwall\" \/>\n<meta property=\"article:published_time\" content=\"2010-08-18T15:45:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-05-18T21:43:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webdesignerwall.mystagingwebsite.com\/wp-content\/uploads\/2010\/08\/hicksdesign.jpg\" \/>\n<meta name=\"author\" content=\"Aigars Silkalns\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@nickla\" \/>\n<meta name=\"twitter:site\" content=\"@nickla\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aigars Silkalns\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries\",\"url\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries\",\"name\":\"CSS3 Media Queries - Web Designer Wall\",\"isPartOf\":{\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/hicksdesign.jpg\",\"datePublished\":\"2010-08-18T15:45:39+00:00\",\"dateModified\":\"2012-05-18T21:43:39+00:00\",\"author\":{\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/#\/schema\/person\/9c6a1ce807a45918d4157d0497157c84\"},\"breadcrumb\":{\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#primaryimage\",\"url\":\"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/hicksdesign.jpg\",\"contentUrl\":\"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/hicksdesign.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS3 Media Queries\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/#website\",\"url\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/\",\"name\":\"Web Designer Wall\",\"description\":\"Design Trends and Tutorials - A wall of design ideas, web trends, and tutorials.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/#\/schema\/person\/9c6a1ce807a45918d4157d0497157c84\",\"name\":\"Aigars Silkalns\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webdesignerwall.mystagingwebsite.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ba8ffcefbaaec481373d85072fdfdae628449bf1ebae707ca57aa3b69dbbf350?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ba8ffcefbaaec481373d85072fdfdae628449bf1ebae707ca57aa3b69dbbf350?s=96&d=mm&r=g\",\"caption\":\"Aigars Silkalns\"},\"sameAs\":[\"https:\/\/webdesignerwall.mystagingwebsite.com\"],\"url\":\"https:\/\/webdesignerwall.com\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CSS3 Media Queries - Web Designer Wall","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries","og_locale":"en_US","og_type":"article","og_title":"CSS3 Media Queries - Web Designer Wall","og_description":"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, you can have one stylesheet for large displays and a different [&hellip;]","og_url":"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries","og_site_name":"Web Designer Wall","article_publisher":"https:\/\/www.facebook.com\/webdesignerwall","article_published_time":"2010-08-18T15:45:39+00:00","article_modified_time":"2012-05-18T21:43:39+00:00","og_image":[{"url":"https:\/\/webdesignerwall.mystagingwebsite.com\/wp-content\/uploads\/2010\/08\/hicksdesign.jpg","type":"","width":"","height":""}],"author":"Aigars Silkalns","twitter_card":"summary_large_image","twitter_creator":"@nickla","twitter_site":"@nickla","twitter_misc":{"Written by":"Aigars Silkalns","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries","url":"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries","name":"CSS3 Media Queries - Web Designer Wall","isPartOf":{"@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#primaryimage"},"image":{"@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#primaryimage"},"thumbnailUrl":"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/hicksdesign.jpg","datePublished":"2010-08-18T15:45:39+00:00","dateModified":"2012-05-18T21:43:39+00:00","author":{"@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/#\/schema\/person\/9c6a1ce807a45918d4157d0497157c84"},"breadcrumb":{"@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#primaryimage","url":"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/hicksdesign.jpg","contentUrl":"https:\/\/webdesignerwall.com\/wp-content\/uploads\/2010\/08\/hicksdesign.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/tutorials\/css3-media-queries#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webdesignerwall.mystagingwebsite.com\/"},{"@type":"ListItem","position":2,"name":"CSS3 Media Queries"}]},{"@type":"WebSite","@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/#website","url":"https:\/\/webdesignerwall.mystagingwebsite.com\/","name":"Web Designer Wall","description":"Design Trends and Tutorials - A wall of design ideas, web trends, and tutorials.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webdesignerwall.mystagingwebsite.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/#\/schema\/person\/9c6a1ce807a45918d4157d0497157c84","name":"Aigars Silkalns","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webdesignerwall.mystagingwebsite.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ba8ffcefbaaec481373d85072fdfdae628449bf1ebae707ca57aa3b69dbbf350?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ba8ffcefbaaec481373d85072fdfdae628449bf1ebae707ca57aa3b69dbbf350?s=96&d=mm&r=g","caption":"Aigars Silkalns"},"sameAs":["https:\/\/webdesignerwall.mystagingwebsite.com"],"url":"https:\/\/webdesignerwall.com\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/posts\/541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/comments?post=541"}],"version-history":[{"count":2,"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/posts\/541\/revisions"}],"predecessor-version":[{"id":988,"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/posts\/541\/revisions\/988"}],"wp:attachment":[{"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/media?parent=541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/categories?post=541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webdesignerwall.com\/wp-json\/wp\/v2\/tags?post=541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}