Other Media Features
Other media features include identifying available output colors with use of the
color
, color-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
.
@media all and (max-width: 420px) {
section, aside {
float: none;
width: auto;
}
}
Identifying Breakpoints
Your instinct might be to write media query breakpoints around common viewport sizes as determined by different device resolutions, such as
320px
, 480px
, 768px
, 1024px
, 1224px
, 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.