Friday 20 December 2013

Responsive Web Design - Part4

Other Media Features

Other media features include identifying available output colors with use of the colorcolor-index, andmonochrome features, identifying bitmap devices with the grid feature, and identifying the scanning process of a television with the scan feature. These features are less common but equally as helpful when needed.

Media Query Browser Support

Unfortunately media queries do not work within Internet Explorer 8 and below, as well as other legacy browsers. There are, however, a couple suitable polyfills written in Javascript.
Respond.js is a lightweight polyfill that only looks for min/max-width media types, which is perfect should those be the only media query types used. CSS3-MediaQueries.js is a more developed, and heavier, polyfill offering support for a larger array of more complex media queries. Additionally, keep in mind any polyfill can have performance concerns, and potentially slow down websites. Make sure that any given polyfill is worth the performance trade off.

Media Queries Demo

Using media queries we will now rewrite the flexible layout we built previously. One of the current problems within the demo appears when the aside width becomes uselessly small within smaller viewports. Adding a media query for viewports under 420 pixels wide we can change the layout by turning off the floats and changing the widths of thesection and aside.
  1. @media all and (max-width: 420px) {
  2. section, aside {
  3. float: none;
  4. width: auto;
  5. }
  6. }
Demo without Media Queries
Fig. 4.02Without any media queries the section and aside become quite small. Perhaps too small to even contain any real content.
Demo with Media Queries
Fig. 4.03Using media queries to remove the floats and change their widths, the section and aside are now able to span the full width of the viewport, allowing breathing room for any existing content.

Identifying Breakpoints

Your instinct might be to write media query breakpoints around common viewport sizes as determined by different device resolutions, such as 320px480px768px1024px1224px, and so forth. This is a bad idea.
When building a responsive website it should adjust to an array of different viewport sizes, regardless of the device. Breakpoints should only be introduced when a website starts to break, look weird, or the experience is being hampered.
Additionally, new devices and resolutions are being released all of the time. Trying to keep up with these changes could be an endless process.