当前位置:网站首页>Page layout - three column layout solution
Page layout - three column layout solution
2022-07-19 01:31:00 【Xu xiaoshuo】
When designing front-end pages , Often left 、 in 、 The layout of the right three columns , Often the left and right columns are a fixed value , And the middle column is adaptive , In the face of such a situation , What kind of design scheme should be used ? This article will introduce five common solutions , These five methods can be selected according to the specific situation , Next, let's introduce one by one .
First let's take a look at the renderings :

Here is the common code part :
<head>
<meta charset="utf-8">
<title> There are five ways to solve the three column layout </title>
<style type="text/css">
html * {
padding: 0;
margin: 0;
}
.layout {
margin-top: 20px;
}
.layout div {
min-height: 100px;
}
</style>
</head>One . Floating solution
<!-- Floating solution -->
<div class="layout float">
<style type="text/css">
.layout.float .left{
float: left;
width: 300px;
background: red;
}
.layout.float .right{
float: right;
width: 300px;
background:red;
}
.layout.float .center{
background: yellow;
}
</style>
<div class="left-right-center">
<div class="left"></div>
<div class="right"></div>
<div class="center">
<h1> Floating solution </h1>
1. This is the middle part of the three column layout
</div>
</div>
</div>The first way is to use float Attribute handle left 、 The right two columns are respectively set to float , The middle part is adaptive , Solve the three column layout .
advantage : Good compatibility , Clear the floating and other elements around the floating , Compatibility is OK .
shortcoming : After setting the float , Out of the document stream , If you can't handle it well , It will bring a lot of problems .
Two 、 Absolute positioning solution
<!-- Absolute positioning solution -->
<div class="layout absolute">
<style type="text/css">
.layout.absolute .left-right-center>div{
position: absolute;
}
.layout.absolute .left{
left: 0;
width: 300px;
background: red;
}
.layout.absolute .center{
left: 300px;
right: 300px;
background: yellow;
}
.layout.absolute .right{
right: 0;
width: 300px;
background: red;
}
</style>
<div class="left-right-center">
<div class="left"></div>
<div class="center">
<h1> Absolute positioning solution </h1>
1. This is the middle part of the three column layout
</div>
<div class="right"></div>
</div>
</div>The second way is to use absolute positioning , Use position:absolute attribute , To three div Absolute positioning , Then use the location attribute , Solve the three column layout .
advantage : quick , It's not easy to have problems
shortcoming : Itself out of the document stream , This causes the child elements to follow out of the document stream , therefore , This leads to poor effectiveness of absolute positioning and usable rows .
3、 ... and 、flexbox Solution
<!-- flexbox Solution -->
<div class="layout flexbox">
<style type="text/css">
.layout.flexbox .left-right-center{
display: flex;
}
.layout.flexbox .left{
width: 300px;
background: red;
}
.layout.flexbox .center{
flex: 1;
background: yellow;
}
.layout.flexbox .right{
width: 300px;
background: red;
}
</style>
<div class="left-right-center">
<div class="left"></div>
<div class="center">
<h1>flexbox Solution </h1>
1. This is the middle part of the three column layout
</div>
<div class="right"></div>
</div>
</div>The third way is to use the style of elastic layout , yes CSS3 New properties display:flex, To the left 、 Set the width in the right two columns , Use... In the middle bar flex Set elastic layout , Solve the three column distribution .CSS3 Layout introduced in , In order to solve the problems of the above two methods , It's a perfect way , Especially for mobile terminals .
Four 、 Table layout solution
<!-- Table layout -->
<div class="layout table">
<style type="text/css">
.layout.table .left-right-center{
width: 100%;
display: table;
height: 100px;
}
.layout.table .left-right-center>div{
display: table-cell;
}
.layout.table .left{
width: 300px;
background: red;
}
.layout.table .center{
background: yellow;
}
.layout.table .right{
width: 300px;
background: red;
}
</style>
<div class="left-right-center">
<div class="left"></div>
<div class="center">
<h1> Table layout solution </h1>
1. This is the middle part of the three column layout
</div>
<div class="right"></div>
</div>
</div>The fourth way is to use table layout , Think of three columns as three columns in a row , Set the height of the table , Three div Set up display:table-cell attribute , Solve the three column layout .
advantage : Table layout is applicable in many scenarios , Its compatibility is also very good , When flex When you can't solve the problem , Table layout is not a way .
shortcoming : There are some historical criticisms , And that is , When one of the cells exceeds the height , Other cells will also be adjusted .
5、 ... and 、 Grid layout solution
<!-- Grid layout -->
<div class="layout grid">
<style type="text/css">
.layout.grid .left-right-center{
width: 100%;
display: grid;
grid-template-rows: 100px;
grid-template-columns: 300px auto 300px;
}
.layout.grid .left{
background: red;
}
.layout.grid .center{
background: yellow;
}
.layout.grid .right{
background: red;
}
</style>
<div class="left-right-center">
<div class="left"></div>
<div class="center">
<h1> Grid layout solution </h1>
1. This is the middle part of the three column layout
</div>
<div class="right"></div>
</div>
</div>The fifth way is to use the new hot spots in recent years , Divide the page into grid styles , Set several rows and columns , Use auto The variable is for the middle column adaptation , Grid layout can make code simpler , Easy to implement logic .
The above is the five ways to solve the three column distribution mentioned in this article , Each method has its own advantages and disadvantages , Different schemes can be selected according to specific design requirements .
边栏推荐
- 单页面应用 SPA 和多页面应用 MPA
- js截取字符串前几位或者截取字符串后几位
- The C Programing Language--(2nd)--笔记--4.11.2
- Day07 ORM table relationship and operation
- mock平台的使用说明
- Day04 routing layer
- XXX packages are looking for funding run `npm fund` for details解决方法
- mmap的 Bus error问题及解决
- About foreign key references, cross domain headers, and ref usage
- uni-app微信小程序——商城(7)——商品详情
猜你喜欢

Oracle database enables archive log mode and archive log deletion and generation frequency
![Stack injection [strong net cup 2019] random note](/img/94/9069ed79e994e3c2e96c3cd1f816ee.png)
Stack injection [strong net cup 2019] random note

JS get the suffix format of a file name

VsCode建立非工程目录下的头文件自动查找
![[elementui El date picker date selector, the end time must not be earlier than the start time, and only the date of the specified number of days from the start time can be selected]](/img/73/af7ca3f670ffee18081b9ca6a9ccf6.png)
[elementui El date picker date selector, the end time must not be earlier than the start time, and only the date of the specified number of days from the start time can be selected]

MoveIt2——2.MoveIt在RViz中的快速入门

网站如何统计访问人数?51LA如何安装使用?

If the website is hacked, what if you jump to other websites through Baidu / Sogou and other search keywords?

cmake的基本使用

wget 警告: 无法验证
随机推荐
Summary of XML external entity injection (xxE target recurrence)
深度之眼三——(7,8)】数学:矩阵对角化及二次型2.3
object-fit:cover;在小程序中不起作用,小程序图片变形了如何处理
服务器如何安装宝塔面板?(宝塔面板安装教程)
Codeforces round #664C
JS intercepts the first few digits of the string or the last few digits of the string
Record buuctf [netding Cup 2018] unfinish1 problem solving ideas
The C Programming Language (2nd)--笔记--1.6
C Programming Language(2nd Edition)--读书笔记--1.5
列表懒加载和图片懒加载
Eye of depth III - (4, 5)] mathematics: matrix eigenvalues and eigenvectors 2
PCRE bypasses regular
Initial flask
Common mode attack and shared prime of RSA
Day07 ORM table relationship and operation
Buuctf [bjdctf2020]ezphp1 detailed explanation
mock平台的使用说明
[SWPU 2019] network TTL encryption and some related knowledge
uni-app微信公众号(1)——网页授权登录
1.互联网基础