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

How to use docker to deploy front-end applications

Docker is becoming more and more popular. It can ...

How to use Web front-end vector icons

Preface When writing front-end pages, we often us...

js to implement collision detection

This article example shares the specific code of ...

Vue implements drag progress bar

This article example shares the specific code of ...

Detailed explanation of MySQL master-slave replication process

1. What is master-slave replication? The DDL and ...

HTML image img tag_Powernode Java Academy

summary Project description format <img src=&q...

Organize the common knowledge points of CocosCreator

Table of contents 1. Scene loading 2. Find Node 1...

JavaScript removes unnecessary properties of an object

Table of contents Example Method 1: delete Method...

Common tags in XHTML

What are XHTML tags? XHTML tag elements are the b...

MySQL pessimistic locking and optimistic locking implementation

Table of contents Preface Actual Combat 1. No loc...

Several ways to store images in MySQL database

Usually the pictures uploaded by users need to be...

An article to understand the advanced features of K8S

Table of contents K8S Advanced Features Advanced ...