About the processing of adaptive layout (using float and margin negative margin)

About the processing of adaptive layout (using float and margin negative margin)
Adaptive layout is becoming more and more common in practical applications. Today I will share several demos of adaptive layout, mainly the floating holy grail layout (also called double-wing layout, which is mainly implemented by floating and negative margin). I did not introduce the absolute positioning layout because I think you can understand the following examples. The absolute positioning layout is also very simple.

PS: The Holy Grail layout has an advantage, which is that it conforms to the concept of progressive enhancement in front-end development. Because the browser parses the DOM from top to bottom, the Holy Grail layout can put the important content section of the page in front of the DOM and parse it first, while the secondary aside content is placed at the back of the DOM and parsed later.
The following example can solve most of the adaptive layout problems in practical applications. Interested students can study it. The code is as follows:

1. Fixed on the left, adaptive on the right (implementation of the Holy Grail layout):

Copy code
The code is as follows:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
body{margin:0;padding:0}
.wrap{ width:100%; float:left}
.content{ height:300px;background:green; margin-left:200px}
.right{ width:200px; height:300px; background:red; float:left; margin-left:-100%}
</style>
</head>
<body>
<div class="wrap">
<div class="content">content</div>
</div>
<div class="right">aside</div>
</body>
</html>

2. Fixed on the right, adaptive on the left (implementation of the Holy Grail layout):

Copy code
The code is as follows:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
body{margin:0;padding:0}
.wrap{ width:100%; float:left}
.content{ height:300px;background:green; margin-right:200px}
.right{ width:200px; height:300px; background:red; float:left; margin-left:-200px;}
</style>
</head>
<body>
<div class="wrap">
<div class="content">content</div>
</div>
<div class="right">aside</div>
</body>
</html>

3. Fixed left and right sides, adaptive middle:

Copy code
The code is as follows:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
body{margin:0;padding:0}
.wrap{ width:100%; float:left}
.content{ height:300px;background:green; margin-left:200px;margin-right:200px}
.left{ width:200px; height:300px; float:left; background:yellow; margin-left:-100%}
.right{ width:200px; height:300px; background:red; float:left; margin-left:-200px}
</style>
</head>
<body>
<div class="wrap">
<div class="content">content</div>
</div>
<div class="left">aside</div>
<div class="right">aside</div>
</body>
</html>

<<:  3 Tips You Must Know When Learning JavaScript

>>:  Introduction to commonly used MySQL commands in Linux environment

Recommend

Solve the problems encountered when installing MySQL 8.0 on Win10 system

The problems and solutions encountered when insta...

How to solve "Unable to start mysql service error 1069"

Today, when I was on the road, a colleague sent m...

Example of implementing text wrapping in html (mixed text and images in html)

1. Text around the image If we use the normal one...

Summary and examples of vue3 component communication methods

The communication modes of vue3 components are as...

How many pixels should a web page be designed in?

Many web designers are confused about the width of...

7 Best VSCode Extensions for Vue Developers

Adding the right VS Code extension to Visual Stud...

WeChat applet implements waterfall flow paging scrolling loading

This article shares the specific code for WeChat ...

The problem of Vue+tsx using slot is not replaced

Table of contents Preface Find the problem solve ...

HTML table tag tutorial (34): row span attribute ROWSPAN

In a complex table structure, some cells span mul...

Vue implements a simple shopping cart example

This article shares the specific code of Vue to i...

Docker implements re-tagging and deleting the image of the original tag

The docker image id is unique and can physically ...

Front-end state management (Part 2)

Table of contents 1. Redux 1.1. Store (librarian)...

Cleverly use CSS3's webkit-box-reflect to achieve various dynamic effects

In an article a long time ago, I talked about the...