当前位置:网站首页>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 .
边栏推荐
- Day06 ORM field and operation
- (六)test命令
- Day12 Association serialization processing
- The eye of Depth III - - (3)] Mathematics: Matrix eigenvalue and eigenvector 1
- Day04 routing layer
- Vue项目部署,清理缓存
- uni-app微信小程序——商城(8)——订单详情
- ModelArts-人声检测and文本分类
- elemtnui 表格如何修改某行文字颜色(elemtnui table 修改某行文字颜色)
- Win10 vscode 代码格式化设置与远程断点调试
猜你喜欢

Oracle database startup and shutdown steps

js字符串转对象 js对象转字符串 js字符串与对象互转

2022年暑假ACM热身练习2(总结)

JS get the suffix format of a file name

自己封装的风格化的开关卡片组件
![Record buuctf [netding Cup 2018] unfinish1 problem solving ideas](/img/29/6cf1eb89f1cbe087438645668ce103.png)
Record buuctf [netding Cup 2018] unfinish1 problem solving ideas

Cve-2022-34265 Django extract & TRUNC SQL injection vulnerability recurrence

当 std::bind 遇上 this

1.互联网基础

深度之眼三——(3)】 数学:矩阵特征值与特征向量1
随机推荐
PCRE bypasses regular
C Programming Language (2nd Edition)--读书笔记--1.5.3
Record once easy_ SQL Stack Injection
Day06 ORM field and operation
wget 警告: 无法验证
Oracle automatic storage management 18C step-by-step installation -2
Oracle database architecture
小程序嵌入网页向小程序跳转并传参,微信小程序中实现公众号授权获取openId
自己封裝的風格化的開關卡片組件
Oracle automatic storage management 18C step-by-step installation -1
uniapp调用地图,进行位置查询,标记定位
Oracle automatic storage management (ASM)
Oracle database startup and shutdown steps
XXX packages are looking for funding run `npm fund` for details解决方法
【ElenmentUI el-date-picker日期选择器,结束时间不得早于开始时间,且只能选择距开始时间指定天数的日期】
微信推送-模版消息参数配置
Codeforces round #664C
Raw Socket抓包,某些端口的数据包抓不到
Registry hijacking triggers malicious programs
JSX 语法