Three-step implementation of responsive page layouts

Source: Internet
Author: User

First step: Meta tags

Most mobile browsers enlarge the HTML page to a wide view (viewport) to match the screen resolution. You can use the META tag of the view to reset it. The following view labels tell the browser to use the width of the device as the width of the view and disallow the initial scaling. Add this meta tag to the

<meta name="viewport" content="width=device-width, initial-scale=1.0  ">  

IE8 or earlier browsers do not support media Query. You can use Media-queries.js or respond.js to add media query support for IE.

<!--[if9]>      <script src="http://css3-mediaqueries-js.googlecode.com/ Svn/trunk/css3-mediaqueries.js"></script>  <![ Endif]-->  

Step Two: HTML structure

In this example, I have a basic page layout that includes the header, content, sidebar, and footer. The head has a fixed height of 180 pixels, the content container is 600 pixels and the sidebar is 300 pixels.

The third step: Media query-media Queries

CSS3 Media query-Media query is the core of responsive design. It tells the browser how to render the page for the specified view width, depending on the condition.
When the view width is less than or equal to 980 pixels, the following rules will take effect. Basically, I'll set all the container widths from pixel values to percentages to make the container size adaptive.

Then specify the width of #content and #sidebar as adaptive and clear float for views less than or equal to 700 pixels, so that the containers are displayed at full width.

For cases less than or equal to 480 pixels (phone screen), set the height of the #header element to adaptive, modify the H1 font size to 24 pixels, and hide the sidebar.

You can add as many media queries as you prefer. I've only shown 3 media queries in the example. The purpose of the media query is to specify different CSS rules for the specified view width to implement different layouts. Media queries can be written in the same or a separate style sheet.

Three-step implementation of responsive page layouts

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.