The CSS3 Media Queries for Responsive web design

Source: Internet
Author: User

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 screenand(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">
03
04 <style>
05 body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td {
06     padding: 0;
07     margin: 0;
08 }
09 .content{
10     zoom:1;
11 }
12 .content:after{
13     content:".";
14     display: block;
15     height: 0;
16     clear: both;
17     visibility: hidden;
18 }
19 .leftBox, .rightBox{
20     float: left;
21     width: 20%;
22     height: 500px;
23     margin: 5px;
24     background: #ffccf7;
25     display: inline;
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;
31 }
32 .middleBox{
33     float: left;
34     width: 50%;
35     height: 800px;
36     margin: 5px;
37     background: #b1fffc;
38     display: inline;
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;
44 }
45 .rightBox{
46     background: #fffab1;
47 }
48 @media only screenand(min-width: 1024px){
49     .content{
50             width: 1000px;
51             margin: auto
52         }
53 }
54 @media only screenand(min-width: 400px)and(max-width: 1024px){
55     .rightBox{
56         width: 0;
57     }
58     .leftBox{ width: 30%}
59     .middleBox{ width: 65%}
60 }
61 @media only screenand(max-width: 400px){
62     .leftBox, .rightBox, .middleBox{
63         width: 98%;
64         height: 200px;
65     }
66 }
67 </style>
68
69  
70
71 <divclass="content">
72   <divclass="leftBox"></div>
73   <divclass="middleBox"></div>
74   <divclass="rightBox"></div>
75 </div>

The CSS3 Media Queries for Responsive web design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.