From:http://www.lamp99.com/responsive-web-design-css3-media-queries.html
Copied over the code a bit messy, is some style, too lazy to get.
Start researching responsive web design, CSS3 Media queries is getting started.
Media Queries, which allows you to apply different style sheets by allowing you to add expressions to determine the environment of your media. In other words, it allows us to change the layout of the page without changing the content to precisely adapt to different devices.
So, MediaHow does the queries work?
Two ways, one is to determine the size of the device directly in link, and then reference a different CSS file:
1 |
<link rel= "stylesheet" type= "text/css" href= "styleA.css" media= "screen and (min-width: 400px)" > |
This means that when the width of the screen is greater than or equal to 400px, the application stylea.css
In the media properties:
- Screen is one of the media types, CSS2.1 defines 10 media types
- and is called a keyword, other keywords also include not (excluding a device), only (qualifying a device)
- (min-width:400px) is the media feature, which is placed in a pair of parentheses. See the relevant Media features section for complete features
1 |
<link rel= "stylesheet" type= "text/css" href= "styleB.css" media= "screen and (min-width: 600px) and (max-width: 800px)" > |
This means that when the width of the screen is greater than 600 and less than 800, the application styleb.css
Other properties can be seen here: http://www.swordair.com/blog/2010/08/431/
Another way, which is written directly in the <style> tag:
1 |
@media screen and (max-width: 600px) { /*当屏幕尺寸小于600px时,应用下面的CSS样式*/} |
The notation is preceded by @media, and the other is the same as the media property in link
Actually basically is the style covers ~, judging the device, and then referencing different style file overrides.
Note that because the page adjusts the layout based on the width of the screen, you cannot use an absolute width layout or an element with an absolute width. This is very important, otherwise a horizontal scroll bar will appear.
——————— Gorgeous Split-line ——————————— –
Here is the demo
A three-column layout, in different sizes, into two columns, and then into a column ~
Code:
01 |
<meta charset= "utf-8" > |
02 |
<meta name= "viewport" content= "width=device-width, initial-scale=1" > |
05 |
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td { |
26 |
-webkit-transition: width 1s ease; |
27 |
-moz-transition: width 1s ease; |
28 |
-o-transition: width 1s ease; |
29 |
-ms-transition: width 2s ease; |
30 |
transition: width 1s ease; |
39 |
-webkit-transition: width 1s ease; |
40 |
-moz-transition: width 1s ease; |
41 |
-o-transition: width 1s ease; |
42 |
-ms-transition: width 1s ease; |
43 |
transition: width 1s ease; |
48 |
@media only screen and (min-width: 1024px){ |
54 |
@media only screen and (min-width: 400px) and (max-width: 1024px){ |
59 |
.middleBox{ width: 65%} |
61 |
@media only screen and (max-width: 400px){ |
62 |
.leftBox, .rightBox, .middleBox{ |
72 |
<div class = "leftBox" ></div> |
73 |
<div class = "middleBox" ></div> |
74 |
<div class = "rightBox" ></div> |
The CSS3 Media Queries for Responsive web design