官术网_书友最值得收藏!

Chapter 2. Media Queries – Supporting Differing Viewports

In the previous chapter, we had a brief look at the essential components for a responsive web page: a fluid layout, fluid images, and media queries.

This chapter will look in detail at media queries, hopefully providing all that's needed to fully understand their capability, syntax, and future development.

In this chapter, we shall:

  • Learn why media queries are needed for a responsive web design
  • Understand the media query syntax
  • Learn how to use media queries in link tags, with CSS @import statements and within CSS files themselves
  • Understand what device features we can test for
  • Use media queries to facilitate visual changes dependent upon available screen space
  • Consider whether media queries should be grouped together or written as and where needed
  • Understand the meta viewport tag, to allow media queries to work as intended on iOS and Android devices
  • Consider the capabilities being proposed for future media queries specifications

The CSS3 specification is made up of a number of modules. Media Queries (Level 3) are just one of these modules. Media queries allow us to target specific CSS styles depending upon the capabilities of a device. For example, with just a few lines of CSS we can change the way content is displayed, dependent upon things such as viewport width, screen aspect ratio, orientation (landscape or portrait), and so on.

Media queries are widely implemented. Pretty much everything other than ancient versions of Internet Explorer (8 and below) support them. In short, there's absolutely no good reason not to be using them!

Tip

Specifications at the W3C go through a ratification process. If you have a spare day, knock yourself out with the official explanation of the process at http://www.w3.org/2005/10/Process-20051014/tr. The simpler version is that specifications go from Working Draft (WD), to Candidate Recommendation (CR), to Proposed Recommendation (PR) before finally arriving, many years later, at W3C Recommendation (REC). Modules at a greater maturity level than others are generally safer to use. For example, CSS Transforms Module Level 3 (http://www.w3.org/TR/css3-3d-transforms/) has been at WD status since March 2009 and browser support for it is far poorer than CR modules such as media queries.

主站蜘蛛池模板: 雷波县| 宜章县| 木里| 安宁市| 定结县| 台中市| 泗洪县| 颍上县| 广元市| 嘉义市| 申扎县| 沁水县| 斗六市| 多伦县| 常熟市| 丹东市| 东乌珠穆沁旗| 綦江县| 尼木县| 宁强县| 信宜市| 新乡县| 衡阳县| 桦甸市| 策勒县| 隆尧县| 伊通| 来凤县| 营口市| 长武县| 昌乐县| 嘉峪关市| 黑水县| 罗江县| 永年县| 枣阳市| 班玛县| 衡阳市| 澳门| 迭部县| 奎屯市|