当前位置:网站首页>三栏布局(中间定宽两边自适应 和 两边定宽中间自适应)
三栏布局(中间定宽两边自适应 和 两边定宽中间自适应)
2022-04-22 06:20:00 【nknmn_】
目录
三栏布局
一. 两边定宽中间自适应
1.flex布局
<div class="container">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
<style>
div{
height: 100px;
}
.container{
display: flex;
}
.center{
flex: 1;
background-color: blue;
}
.left,.right{
width: 100px;
background-color: red;
}
</style>
2.浮动 + margin
<div class="container">
<div class="left">left</div>
<div class="right">right</div>
<div class="center">center</div> <!-- 注意此时center在最后面-->
</div>
<style>
div{
height: 100px;
}
.left{
float: left;
width: 100px;
background-color: red;
}
.center{
margin: 0 100px;
background-color: blue;
}
.right{
float: right;
width: 100px;
background-color: red;
}
</style>
3.浮动 + calc()
<div class="container">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
<style>
div {
height: 100px;
}
.left {
float: left;
width: 100px;
background-color: red;
}
.center {
float: left;
width: calc(100% - 200px);
background-color: blue;
}
.right {
float: right;
width: 100px;
background-color: red;
}
</style>
4.定位
<div class="container">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
<style>
div {
height: 100px;
}
.container {
position: relative;
}
.left {
position: absolute;
left: 0;
width: 100px;
background-color: red;
}
.center {
position: absolute;
left: 100px;
width: calc(100% - 200px);
background-color: blue;
}
.right {
position: absolute;
right: 0;
width: 100px;
background-color: red;
}
</style>
5.表格布局
<div class="container">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
<style>
div{
height: 100px;
}
.container {
display: table;
width: 100%;
}
.container>div {
display: table-cell;
}
.center{
background-color: blue;
}
.left,.right{
width: 100px;
background-color: red;
}
</style>
6.网格布局
<div class="container">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
<style>
div{
height: 100px;
}
.container {
display: grid;
width: 100%;
grid-template-columns: 100px auto 100px;
}
.left,.right{
background-color: red;
}
.center{
background-color: blue;
}
</style>
7.圣杯布局
<div class="header">头部</div>
<div class="container clearfix">
<div class="center">主区域(优先加载)</div>
<div class="left">左区域</div>
<div class="right">右区域</div>
</div>
<div class="footer">底部</div>
<style>
.clearfix::after{
content: "";
display: block;
clear: both;
}
div{
height: 100px;
}
.header,.footer{
background-color: yellow;
}
.container{
padding: 0 100px;
}
.center,.left,.right{
float: left;
}
.center{
width: 100%;
background-color: red;
}
.left{
position: relative;
left: -100px;
margin-left: -100%;
width: 100px;
background-color: blue;
}
.right{
position: relative;
right: -100px;
margin-left: -100px;
width: 100px;
background-color: green;
}
</style>
8.双飞翼布局
<div class="header">头部</div>
<div class="container clearfix">
<div class="wrapper">
<div class="center">主区域(优先加载)</div>
</div>
<div class="left">左区域</div>
<div class="right">右区域</div>
</div>
<div class="footer">底部</div>
<style>
.clearfix::after {
content: "";
display: block;
clear: both;
}
div {
height: 100px;
}
.header,
.footer {
background-color: yellow;
}
.wrapper{
width: 100%;
float: left;
}
.center {
margin: 0 100px;
background-color: red;
}
.left {
width: 100px;
float: left;
margin-left: -100%;
background-color: blue;
}
.right {
width: 100px;
float: left;
margin-left: -100px;
background-color: green;
}
</style>
二. 中间定宽两边自适应
1.flex布局
<div class="container">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
<style>
div{
height: 100px;
}
.container{
display: flex;
}
.left,right{
flex: 1;
background-color: red;
}
.center{
width: 1250px;
height: 500px;
background-color: yellow;
}
</style>
2.浮动布局
<div class="container">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
<style>
div{
height:100px
}
.center{
float: left;
width: 1250px;
background-color: blue;
}
.left,.right{
float: left;
width: calc(50% - 625px);
background-color: red;
}
</style>
3.margin负值
<div class="container">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
<style>
div{
height: 100px;
}
.center {
width: 1000px;
float: left;
background-color: yellow;
}
.left {
float: left;
width: 50%;
margin-left: -500px;
background-color: red;
}
.right {
float: right;
width: 50%;
margin-right: -500px;
background-color: blue;
}
</style>
4.display:-webkit-box;
<div class="container ">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
<style>
div{
height:100px
}
.container{
display: -webkit-box;
}
.left,.right{
-webkit-box-flex: 1;
background-color: blue;
}
.center{
width: 1250px;
background-color: red;
}
</style>
版权声明
本文为[nknmn_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_50829019/article/details/124200861
边栏推荐
- L1-064 AI core code valued at 100 million (20 points) has wrong format
- The art of concurrent programming (9): the use and principle of final
- Yapi的安装与配置(转载)
- E.Figure Skating (字符串排序/签到) (2021年度训练联盟热身训练赛第五场 )
- Hand tearing algorithm -- LRU cache elimination strategy, asked so often
- Codeforces Round #780 (Div. 3)
- Final关键字
- Dom 文档对象模型
- 1232. Minimum number of arrows for exploding balloons
- CF1547E Air Conditioners
猜你喜欢
![P1095 [noip2007 popularity group] escape of the catcher](/img/5e/0437bdee83b6b66626e535e382b84b.png)
P1095 [noip2007 popularity group] escape of the catcher

Detailed explanation of linked list exercises

APC(三)

Quick sort and merge sort

Redis的设计与实现(1):了解数据结构与对象

Pointer structure const summary

1005 Monopoly 同余求解(2021中国大学生程序设计竞赛CCPC-网络选拔赛重赛)

363 · rainwater connection

L1-071 前世档案 (20 分) (类似二分)

Detailed bubble sequence and array name
随机推荐
Codeforces Round #778
Blog synchronization update notification
867 · four key keyboard
深入理解MySQL(7):MySQL如何调优
Codeforces Round #588 (Div. 2) C D
B. Ball Dropping (简单几何计算 / 相似三角形) (2021牛客暑期多校训练营1)
Codeforces Round #776 (Div. 3)
APC(一)
Codeforces Round #634 (Div. 3)
A.Binary Seating (概率) (2021年度训练联盟热身训练赛第五场)
189. Rotation array
15. Full arrangement
Detailed overview of this keyword
Educational Codeforces Round 122 (Rated for Div. 2)
Detailed bubble sequence and array name
Longest ascending sequence
C.Ducky Debugging(简单判断/签到)(2021年度训练联盟热身训练赛第五场 )
E. Figure skiing (string sorting / check-in) (Game 5 of 2021 training League warm-up training competition)
并发编程的艺术(3):深入理解Synchronized的原理
A. Binary seating (the fifth game of 2021 training League warm-up training competition)