Table of Contents
Step one: Add a line of viewport meta tags at the head of the web page code
Step 2: Fluid Layout
Step 3: CSS @media rules, selective loading of CSS
Step 4: Do not use absolute width, font size
Step 5: Adaptation of the image
Home Web Front-end HTML Tutorial What is responsive layout? Implementation of html responsive layout

What is responsive layout? Implementation of html responsive layout

Aug 06, 2018 pm 04:31 PM

This article brings you the content about what is responsive layout? The implementation of html responsive layout has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Step one: Add a line of viewport meta tags at the head of the web page code

(1)viewport is the default width and height of the web page. The meaning of the above line of code is : The width of the web page is equal to the screen width by default (width=device-width), and the original scaling ratio (initial-scale=1) is 1.0, that is, the initial size of the web page occupies 100% of the screen area.

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
Copy after login

All major browsers support this setting, including IE9. For those older browsers (mainly IE6, 7, 8), you need to use css3-mediaqueries.js.

<!--[if lt IE 9]>      
    <script src="http://css3-mediaqueries- js.googlecode.com/svn/trunk/css3-mediaqueries.js">
    </script> 
<![endif]-->
Copy after login

(2) X-UA-Compatible

X-UA-Compatible is a newly added setting since IE8 and is not recognized by browsers below IE8. By setting the value of X-UA-Compatible in meta, you can specify the compatibility mode settings of the web page.

#IE browser, regardless of whether a DTD is used to declare the document standard, IE8/9 will use the IE7 engine to render the page.

<meta http-equiv="X-UA-Compatible" content="IE=7">
Copy after login

#IE browser, IE8/9 will use the IE8 engine to render the page.

<meta http-equiv="X-UA-Compatible" content="IE=8">
Copy after login

#IE browser, IE8/9 and later versions will use the highest version of IE to render the page.

<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
<meta http-equiv="X-UA-Compatible" content="IE=7,9">
Copy after login

#IE=edge tells IE to use the latest engine to render web pages, and chrome=1 can activate Chrome Frame.

The chrome=1 here does not mean that IE's technology has been enhanced to simulate the Chrome browser, but is related to the Google Chrome Frame (Google Embedded Browser Framework GCF) developed by Google. This plug-in can keep the appearance of the user's IE browser unchanged, but the user is actually using the Chrome kernel when browsing the web, and supports IE6/7/8 on Windows XP and above.

<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
Copy after login

Step 2: Fluid Layout

The position of each block in the page is floating, not fixed. If the width is too small, two elements cannot be placed, and the following The element will automatically scroll to the bottom of the previous element and will not overflow in the horizontal direction, avoiding the appearance of the horizontal scroll bar

.left{ width:30%; float:left}
.right{ width:70%; float:right;}
Copy after login

Step 3: CSS @media rules, selective loading of CSS

@media screen and (max-device-width: 400px) {  .left{ float:none;} }
Copy after login

When the screen is smaller than 400, left cancels the floating.

The core of "adaptive web design" is the Media Query module introduced by CSS3. Automatically detect the screen width and then load the corresponding CSS file. If the screen width is less than 600 pixels (max-device-width: 600px), load the css600.css file. If the screen width is between 600 pixels and 980 pixels, the css600-980.css file is loaded.

<link rel="stylesheet" type="text/css" media="screen and (max-device-width: 600px)" href="style/css/css600.css" />
<link rel="stylesheet" type="text/css" media="screen and (min-width: 600px) and (max-device-width: 980px)" href="css600-980.css" />
Copy after login

In addition to loading CSS files with html tags, you can also load them in existing CSS files

@import url("css600.css") screen and (max-device-width: 600px);
Copy after login

Step 4: Do not use absolute width, font size

(1 ) width:auto; / width:XX%;

(2) The font size is 100% of the default size of the page, which is 16 pixels. Do not use the absolute size "PX" for the font, but use the relative size "REM"

html{font-size:62.5%;} body {font:normal 100% Arial,sans-serif;font-size:14px; font-size:1.4rem;
Copy after login

Step 5: Adaptation of the image

"Adaptive web design" must also implement automatic scaling of the image .

img, object {max-width: 100%;}
Copy after login

The old version of IE does not support max-width, so it has to be written as:

img {width: 100%;}
Copy after login

When scaling images on the windows platform, image distortion may occur. At this time, you can try to use IE's proprietary command

img { width:100%; -ms-interpolation-mode: bicubic;}
Copy after login

or use js--imgSizer.js

addLoadEvent(function() {     
        var imgs = document.getElementById("content").getElementsByTagName("img");           
        imgSizer.collate(imgs);   
});
Copy after login

Recommended related articles:

Replace or How to write the code to add a website background image? (Example)

Introduction to the table tag

in HTML (with code)

Introduction to flexible layout (Flex) in HTML (with code)

The above is the detailed content of What is responsive layout? Implementation of html responsive layout. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1258
29
C# Tutorial
1232
24
Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

See all articles