Using media query to implement responsive design

Source: Internet
Author: User

Your Web page will look good on your phone. The mystery of completing this task is called responsive Design, and media query is the key to implementing a Web page response.

On the computer an example:

<Divclass= "Row">     <Divclass= "Span4">...</Div>     <Divclass= "Span4">...</Div>     <Divclass= "Span4">...</Div></Div>

CSS style:

. Row {  width:100%;} . Span {  width:300px;   float:left;   margin-left:30px;}

This is displayed on the computer, is normal, on a certain device layout is not what we expect.

Media Query

Sets the criteria for applying the appropriate style outside of the CSS. There are some features that you can use to decide which styles to apply. Here are some of the important parts:

. Width

. Height

. Device width

. Device height

. Resolution

. Orientation

. Aspect ratio

Determines what style to use by device width. The appropriate rules below.

@media (max-width:500px)

Use a CSS style when the screen width is less than 500px. This style condition is true before it is referenced.

There are three different ways to apply this conditional rule:

1, <link> tag

as follows: <lin rel = "Stylesheel" type= "text/css" media= "screen and (max-width:500px)" href= "Test.css" >

2. Media condition

A piece of CSS code can be enclosed in curly braces, and the CSS definition works only when media query satisfies the following criteria:

@media screen and        (max-width:500px){            . row{                     width:100%;  }               . span{ width:auto;  Float:left;       margin:0; }       } 

3. Import condition

A reference only imports the external CSS when the media query condition is satisfied. CSS styles defined in an external file are only valid if the condition is satisfied.

@import url ("test.css") screen and (max-width:500px);

We can use media query to change the layout of the page, but it is also possible to use them to make CSS definitions similar to the conditions. We often change the font size, image quality, whitespace and other elements

To better adapt to different types of equipment.

Using media query to implement responsive design

Related Article

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.