{"id":24679,"date":"2012-05-01T00:00:00","date_gmt":"2012-05-01T00:00:00","guid":{"rendered":"https:\/\/alienroad.com\/google-bilgi-bankasi\/responsive-design-harnessing-the-power-of-media-queries\/"},"modified":"2012-05-01T00:00:00","modified_gmt":"2012-05-01T00:00:00","slug":"responsive-design-harnessing-the-power-of-media-queries","status":"publish","type":"ar_kb","link":"https:\/\/alienroad.com\/google-bilgi-bankasi\/responsive-design-harnessing-the-power-of-media-queries\/","title":{"rendered":"Responsive design \u2013 harnessing the power of media queries"},"content":{"rendered":"<p class=\"gargardate\">Tuesday, May 01, 2012<\/p>\n<p>\n  We love data, and spend a lot of time monitoring the analytics on our websites. Any web developer<br \/>\n  doing the same will have noticed the increase in traffic from mobile devices of late. Over the<br \/>\n  past year we&#8217;ve seen many key sites garner a significant percentage of pageviews from smartphones<br \/>\n  and tablets. These represent large numbers of visitors, with sophisticated browsers which support<br \/>\n  the latest HTML, CSS, and JavaScript, but which also have limited screen space with widths as<br \/>\n  narrow as 320 pixels.\n<\/p>\n<p>\n  Our commitment to<br \/>\n  <a href=\"https:\/\/www.google.com\/accessibility\/\" class=\"external-link\">accessibility<\/a> means we<br \/>\n  strive to provide a good browsing experience for all our users. We faced a stark choice between<br \/>\n  creating mobile specific websites, or adapting existing sites and new launches to render well on<br \/>\n  both desktop and mobile. Creating two sites would allow us to better target specific hardware, but<br \/>\n  maintaining a single shared site preserves a canonical URL, avoiding any complicated redirects,<br \/>\n  and simplifies the sharing of web addresses. With a mind towards maintainability we leant towards<br \/>\n  using the same pages for both, and started thinking about how we could fulfill the following<br \/>\n  guidelines:\n<\/p>\n<ol>\n<li><b>Our pages should render legibly at any screen resolution<\/b><\/li>\n<li><b>We mark up one set of content, making it viewable on any device<\/b><\/li>\n<li><b>We should never show a horizontal scrollbar, whatever the window size<\/b><\/li>\n<\/ol>\n<p><img decoding=\"async\" alt=\"The Chromebook marketing site is stacking content, tweaking navigation, and rescaling images based on the device of the user\" height=\"390\" src=\"https:\/\/alienroad.com\/wp-content\/uploads\/kb-gorsel\/g-fac4bbc1d5c8.jpg\" loading=\"lazy\" width=\"400\"><\/p>\n<h2 id=\"implementation\" tabindex=\"-1\">Implementation<\/h2>\n<p>\n  As a starting point, simple, semantic markup gives us pages which are more flexible and easier to<br \/>\n  reflow if the layout needs to be changed. By ensuring the stylesheet enables a<br \/>\n  <a href=\"https:\/\/www.alistapart.com\/articles\/responsive-web-design\/\" class=\"external-link\">liquid layout<\/a>,<br \/>\n  we&#8217;re already on the road to mobile-friendliness. Instead of specifying <code>width<\/code> for<br \/>\n  container elements, we started using <code>max-width<\/code> instead. In place of<br \/>\n  <code>height<\/code> we used <code>min-height<\/code>, so larger fonts or multi-line text don&#8217;t<br \/>\n  break the container&#8217;s boundaries. To prevent fixed width images &#8220;propping open&#8221; liquid columns,<br \/>\n  we apply the following CSS rule:\n<\/p>\n<div><\/div>\n<p>\n  Liquid layout is a good start, but can lack a certain finesse. Thankfully<br \/>\n  <a href=\"https:\/\/www.w3.org\/TR\/css3-mediaqueries\/\" class=\"external-link\">media queries<\/a> are now<br \/>\n  <a href=\"https:\/\/www.caniuse.com\/#search=media+queries\" class=\"external-link\">well-supported in modern browsers<\/a><br \/>\n  including IE9+ and most mobile devices. These can make the difference between a site that degrades<br \/>\n  well on a mobile browser, vs. one that is enhanced to take advantage of the streamlined UI. But<br \/>\n  first we have to take into account how smartphones represent themselves to web servers.\n<\/p>\n<h2 id=\"viewports\" tabindex=\"-1\">Viewports<\/h2>\n<p>\n  When is a pixel not a pixel? When it&#8217;s on a smartphone. By default, smartphone browsers pretend to<br \/>\n  be high-resolution desktop browsers, and lay out a page as if you were viewing it on a desktop<br \/>\n  monitor. This is why you get a tiny-text &#8220;overview mode&#8221; that&#8217;s impossible to read before zooming<br \/>\n  in. The<br \/>\n  <a href=\"https:\/\/developer.android.com\/guide\/webapps\/targeting.html\" class=\"external-link\">default viewport width<\/a><br \/>\n  for the default Android browser is 800px, and 980px for iOS, regardless of the number of<br \/>\n  <a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_displays_by_pixel_density\" class=\"external-link\">actual physical pixels<\/a><br \/>\n  on the screen.\n<\/p>\n<p>\n  In order to trigger the browser to render your page at a more readable scale, you need to use the<br \/>\n  viewport meta element:\n<\/p>\n<div><\/div>\n<p>\n  Mobile screen resolutions vary widely, but most modern smartphone browsers currently report a<br \/>\n  standard <code>device-width<\/code> in the region of 320px. If your mobile device actually has a<br \/>\n  width of 640 physical pixels, then a 320px wide image would be sized to the full width of the<br \/>\n  screen, using double the number of pixels in the process. This is also the reason why text looks<br \/>\n  so much crisper on the small screen \u2013 double the pixel density as compared to a standard desktop<br \/>\n  monitor.\n<\/p>\n<p>\n  The useful thing about setting the <code>width<\/code> to <code>device-width<\/code> in the viewport<br \/>\n  <code>meta<\/code> tag is that it updates when the user changes the orientation of their smartphone or tablet.<br \/>\n  Combining this with media queries allows you to tweak the layout as the user rotates their device:\n<\/p>\n<div><\/div>\n<p>\n  In reality you may find you need to use different breakpoints depending on how your site flows and<br \/>\n  looks on various devices. You can also use the <code>orientation<\/code> media query to target<br \/>\n  specific orientations without referencing pixel dimensions,<br \/>\n  <a href=\"https:\/\/caniuse.com\/#search=orientation\" class=\"external-link\">where supported<\/a>.\n<\/p>\n<div><\/div>\n<p><img decoding=\"async\" alt=\"The Cultural Institute site stacks content differently and shows different image sizes for different devices\" height=\"400\" src=\"https:\/\/alienroad.com\/wp-content\/uploads\/kb-gorsel\/g-84c2eb84c4a0.jpg\" loading=\"lazy\" width=\"381\"><\/p>\n<h2 id=\"a-media-queries-example\" tabindex=\"-1\">A media queries example<\/h2>\n<p>\n  We recently re-launched the<br \/>\n  <a href=\"https:\/\/www.google.com\/about\/\" class=\"external-link\">About Google<\/a> page. Apart from<br \/>\n  setting up a liquid layout, we added a few media queries to provide an improved experience on<br \/>\n  smaller screens, like those on a tablet or smartphone.\n<\/p>\n<p>\n  Instead of targeting specific device resolutions we went with a relatively broad set of<br \/>\n  breakpoints. For a screen resolution wider than 1024 pixels, we render the page as it was<br \/>\n  originally designed, according to our 12-column grid. Between 801px and 1024px, you get to see a<br \/>\n  slightly squished version thanks to the liquid layout.\n<\/p>\n<p>\n  Only if the screen resolution drops to 800 pixels will content that&#8217;s not considered core content<br \/>\n  be sent to the bottom of the page:\n<\/p>\n<div><\/div>\n<p>With a final media query we enter smartphone territory:<\/p>\n<div><\/div>\n<p>\n  At this point, we&#8217;re not loading the large image anymore and we stack the content blocks. We also<br \/>\n  added additional whitespace between the content items so they are more easily identified as<br \/>\n  different sections.\n<\/p>\n<p>With these simple measures we made sure the site is usable on a wide range of devices.<\/p>\n<p><img decoding=\"async\" alt=\"The About Google site stacks content and even removes images for different devices\" height=\"400\" src=\"https:\/\/alienroad.com\/wp-content\/uploads\/kb-gorsel\/g-f3daeab7e9ac.jpg\" loading=\"lazy\" width=\"396\"><\/p>\n<h2 id=\"conclusion\" tabindex=\"-1\">Conclusion<\/h2>\n<p>\n  It&#8217;s worth bearing in mind that there&#8217;s no simple solution to making sites accessible on mobile<br \/>\n  devices and narrow viewports. Liquid layouts are a great starting point, but some design<br \/>\n  compromises may need to be made. Media queries are a useful way of adding polish for many devices,<br \/>\n  but remember that<br \/>\n  <a href=\"https:\/\/caniuse.com\/#search=media%20queries\" class=\"external-link\">25% of visits<\/a> are<br \/>\n  made from those desktop browsers that do not currently support the technique and there are some<br \/>\n  <a href=\"https:\/\/www.slideshare.net\/guypod\/performance-implications-of-mobile-design\/28\" class=\"external-link\">performance implications<\/a>.<br \/>\n  And if you have a fancy widget on your site, it might work beautifully with a mouse, but not so<br \/>\n  great on a touch device where fine control is more difficult.\n<\/p>\n<p>\n  The key is to test early and test often. Any time spent surfing your own sites with a smartphone<br \/>\n  or tablet will prove invaluable. When you can&#8217;t test on real devices, use the<br \/>\n  <a href=\"https:\/\/developer.android.com\/sdk\/index.html\" class=\"external-link\">Android SDK<\/a> v\u0259 ya<br \/>\n  <a href=\"https:\/\/developer.apple.com\/devcenter\/ios\/index.action\" class=\"external-link\">iOS Simulator<\/a>.<br \/>\n  Ask friends and colleagues to view your sites on their devices, and watch how they interact too.\n<\/p>\n<p>\n  Mobile browsers are a great source of new traffic, and learning how best to support them is an<br \/>\n  exciting new area of professional development.\n<\/p>\n<p>Some more examples of responsive design at Google:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.google.com\/about\/\" class=\"external-link\">www.google.com\/about\/<\/a><\/li>\n<li><a href=\"https:\/\/www.google.com\/goodtoknow\" class=\"external-link\">www.google.com\/goodtoknow<\/a><\/li>\n<li><a href=\"https:\/\/www.google.com\/culturalinstitute\" class=\"external-link\">www.google.com\/culturalinstitute<\/a><\/li>\n<li><a href=\"https:\/\/www.google.com\/events\/sciencefair\" class=\"external-link\">www.google.com\/events\/sciencefair<\/a><\/li>\n<li><a href=\"https:\/\/www.google.com\/intl\/en\/chrome\/devices\" class=\"external-link\">www.google.com\/intl\/en\/chrome\/devices<\/a><\/li>\n<li><a href=\"https:\/\/picasa.google.com\/\" class=\"external-link\">picasa.google.com<\/a><\/li>\n<\/ul>\n<p class=\"byline-author\">\n  Written by <a href=\"https:\/\/plus.google.com\/111296156124188875659\/about\" rel=\"author\" class=\"external-link\">Rupert Breheny<\/a>,<br \/>\n  <a href=\"https:\/\/plus.google.com\/114073068697999578001\/about\" rel=\"author\" class=\"external-link\">Edward Jung<\/a>, and<br \/>\n  <a href=\"https:\/\/plus.google.com\/101131853496921328128\/about\" rel=\"author\" class=\"external-link\">Matt Z\u00fcrrer<\/a>, Google Webmaster Team<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tuesday, May 01, 2012 We love data, and spend a lot of time monitoring the analytics on our websites. Any web developer doing the same will have noticed the increase in traffic from mobile devices of late. Over the past year we&#8217;ve seen many key sites garner a significant percentage of pageviews from smartphones and [&hellip;]<\/p>\n","protected":false},"menu_order":84539,"template":"","meta":{"footnotes":""},"ar_kb_kategori":[665],"ar_kb_etiket":[],"class_list":["post-24679","ar_kb","type-ar_kb","status-publish","has-post-thumbnail","hentry","ar_kb_kategori-blog"],"_links":{"self":[{"href":"https:\/\/alienroad.com\/wp-json\/wp\/v2\/ar_kb\/24679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alienroad.com\/wp-json\/wp\/v2\/ar_kb"}],"about":[{"href":"https:\/\/alienroad.com\/wp-json\/wp\/v2\/types\/ar_kb"}],"version-history":[{"count":0,"href":"https:\/\/alienroad.com\/wp-json\/wp\/v2\/ar_kb\/24679\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alienroad.com\/wp-json\/wp\/v2\/media\/26935"}],"wp:attachment":[{"href":"https:\/\/alienroad.com\/wp-json\/wp\/v2\/media?parent=24679"}],"wp:term":[{"taxonomy":"ar_kb_kategori","embeddable":true,"href":"https:\/\/alienroad.com\/wp-json\/wp\/v2\/ar_kb_kategori?post=24679"},{"taxonomy":"ar_kb_etiket","embeddable":true,"href":"https:\/\/alienroad.com\/wp-json\/wp\/v2\/ar_kb_etiket?post=24679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}