Responsive layout summary (recommended)

Responsive layout summary (recommended)

Basic knowledge of responsive layout development

This chapter is mainly divided into the following parts

• Correct understanding of responsive design
• Steps to responsive design
• Issues that need to be paid attention to in responsive design
• Principles of implementing responsive web page layout

First: Correctly understand responsive layout

Responsive web design means that a website can be compatible with multiple terminals - instead of making a specific version for each terminal. For example: there are many responsive products in society now, such as folding sofas, folding beds, etc. When we need to put the sofa in a corner, the sofa is like a div, and a place in the corner is like a parent element. Due to the change of the parent element space, we have to adjust the div so that it can still be placed in the corner. In the project, you will encounter different terminals. Due to different terminal resolutions, if you want to provide a better user experience, it is necessary to make your page compatible with multiple terminals.

Second: Steps of Responsive Design

Now that we understand what responsiveness is, let's talk about the steps of responsive design. Some people may say, "Blogger, are you stupid? Aren't the steps of responsive design just 1. Write non-responsive code, 2. Process it into responsive code, 3. Handle responsive details, and 4. Complete responsive development?" The blogger was shocked. It turned out that there are many masters among the people. He smiled slightly to show his respect. Oh my god, I said it wrong. It should be smiled slightly. Don't misunderstand me.

Now, getting back to the topic, since the blogger is a person who wants to get to the bottom of things, I will dig deep into the roots of responsive design and have a deeper understanding of these four steps.

1. Layout and setting meta tags

When creating a responsive website, or making a non-responsive website responsive, the first thing to focus on is the layout of the elements. When I create a responsive layout, I usually write a non-responsive layout first, with a fixed width of the page. I don't think this will be difficult for anyone here. If the non-responsiveness is done, then I will add media queries and responsive code. This operation makes it easier to implement responsive features.

When you are done When you have finished your non-responsive website, the first thing to do is in your HTML page, paste the following code between the and tags. This will set the screen to a 1:1 display size, providing full view of the site on the iPhone and other smartphone browsers, and preventing users from zooming the page.

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "viewport"   content = "width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" >   
  2. < meta   http-equiv = "X-UA-Compatible"   content = "IE=edge,chrome=1" >   
  3. < meta   name = "HandheldFriendly"   content = "true" >   
  4. The user-scalable attribute can solve the problem that after the iPad switches to landscape mode, it takes touch to return to the specific size.

2. Set styles through media queries

Media query is the core of responsive design. It can communicate with the browser and tell the browser how to present the page. If the resolution of a terminal is less than 980px, you can write it like this

XML/HTML CodeCopy content to clipboard
  1. @media screen and (max-width:980px) {
  2. #head { … }
  3. #content { … }
  4. #footer { … }
  5. The styles here will override the previously defined styles.

3. Set multiple view widths

If we want to be compatible with iPad and iPhone views, we can set it like this:

XML/HTML CodeCopy content to clipboard
  1. /**ipad**/
  2. @media only screen and (min-width:768px)and(max-width:1024px){}
  3. /**iphone**/
  4. @media only screen and (width:320px)and (width:768px){}

3. Font settings

So far, most of the font units used by developers are pixels. Although pixels are OK on ordinary websites, we still need responsive fonts. A responsive font should be relative to the width of its parent container so that it can adapt to the client screen.

CSS3 introduces a new unit called rem, which is similar to em but more convenient to use for HTML elements.

rem is relative to the root element, don't forget to reset the root element font size:

XML/HTML CodeCopy content to clipboard
  1. html{font-size:100%;}
  2. Once you have done that, you can define your responsive fonts:
  3. @media (min-width:640px){body{font-size:1rem;}}
  4. @media (min-width:960px){body{font-size:1.2rem;}}
  5. @media (min-width:1200px){body{font-size:1.5rem;}}
  6. For those who don’t understand rem, here is a good blog I would like to recommend to you (http://www.cnblogs.com/YYvam1288/p/5123272.html)

4. Issues that need to be paid attention to in responsive design

1. The width is not fixed, you can use percentage

XML/HTML CodeCopy content to clipboard
  1. #head{width:100%;}
  2. #content{width:50%;}

2. Image processing

Here I give everyone a key. Some people may say, blogger, can you please stop showing off? What key is there for image processing? Do you think it is to open the door? Blogger, wake up!

Ouch, what a bad temper I have. The key I mentioned is not a real key, but a universal method of image processing. What is it? The picture is liquefied. Then someone will ask: "What is image liquefaction?" This is a very good question. I will give you 99 points. I would give you one more point because I am afraid you might become too proud. As we all know, water is invisible and can fit into many containers. So if we regard the image as water, can we solve the image adaptation problem?

For images in HTML pages, such as images inserted in articles, we can use the CSS style max-width to control the maximum width of the image, such as:

XML/HTML CodeCopy content to clipboard
  1. #wrap img{
  2. max-width:100%;
  3. height:auto;
  4. }
  5. After this setting, the image with ID wrap will be expanded to the same width as the width of wrap. The setting of height to auto is to ensure the original height-to-width ratio of the image so that the image will not be distorted.

In addition to images in the img tag, we often encounter background images, such as logos as background images:

XML/HTML CodeCopy content to clipboard
  1. #log a{display:block;
  2. width:100%;
  3. height:40px;
  4. text-indent:55rem;
  5. background-img:url(logo.png);
  6. background-repeat:no-repeat;
  7. background-size:100% 100%;
  8. }
  9. Background-size is a new attribute of CSS3, which is used to set the size of the background image. There are two optional values. The first value is used to specify the width of the background image, and the second value is used to specify the height of the background image. If only one value is specified, the other value defaults to auto.
  10. background-size:cover; Expand the image proportionally to fill the element
  11. background-size:contain; proportionally scales the image down to fit the size of the element

Finally, let's summarize the implementation principles of responsive layout

First of all, we should follow the principle of mobile first, with interaction and design mainly based on mobile, and PC as an extension of mobile. A page needs to be compatible with different terminals, so there are two key points we need to make responsive: responsive layout and responsive content (pictures, multimedia)

XML/HTML CodeCopy content to clipboard
  1. 1. Responsive Layout
  2. 1. Meta tag definition
  3. 2. Use Media Queries to adapt the corresponding style
  4. 2. Responsive Content
  5. 1. Responsive Images

I know what you are expecting. No picture, no truth. No dome, isn't that nonsense? It's just talk. Don't worry, I won't be beaten like this. Here is my personal responsive layout dome.

XML/HTML CodeCopy content to clipboard
  1. git html code https://github.com/lifenglei/mygit/blob/master/xiang.html
  2. CSS code https://github.com/lifenglei/mygit/blob/master/xiang.css

Well, here is the result of the blogger’s hard work. Next time I will summarize the layout of the mobile terminal.

The above responsive layout summary (recommended) is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

Original URL: http://www.cnblogs.com/dreamsboy/archive/2016/07/09/5656009.html

<<:  JS implements the curriculum timetable applet (imitating the super curriculum timetable) and adds a custom background function

>>:  Solution to using html2canvas to process Dom elements with Baidu map into images

Recommend

Detailed explanation of the solution to forget the password in MySQL 5.7

ENV: [root@centos7 ~]# uname -r 3.10.0-514.el7.x8...

Detailed explanation of Vue3 life cycle functions and methods

1. Overview The so-called life cycle function is ...

Web designer is a suitable talent

<br />There is no road in the world. When mo...

CSS clear float clear:both example code

Today I will talk to you about clearing floats. B...

3 simple ways to achieve carousel effects with JS

This article shares 3 methods to achieve the spec...

Optimal web page width and its compatible implementation method

1. When designing a web page, determining the widt...

HTML+CSS+JS realizes the scrolling gradient effect of the navigation bar

Table of contents First look at the effect: accom...

Detailed steps to configure MySQL remote connection under Alibaba Cloud

Preface As we all know, by default, the MySQL ins...

Using zabbix to monitor the ogg process (Windows platform)

This article introduces how to monitor the ogg pr...

How to create a virtual environment using virtualenv under Windows (two ways)

Operating system: windowns10_x64 Python version: ...

Solution to overflow of html table

If the table is wide, it may overflow. For exampl...

HTML+VUE paging to achieve cool IoT large screen function

Effect demo.html <html> <head> <me...

VMWare Linux MySQL 5.7.13 installation and configuration tutorial

This article shares with you the tutorial of inst...

Reasons why MySQL queries are slow

Table of contents 1. Where is the slowness? 2. Ha...

How to modify the location of data files in CentOS6.7 mysql5.6.33

Problem: The partition where MySQL stores data fi...