当前位置:网站首页>常见布局效果实现方案
常见布局效果实现方案
2022-08-11 03:41:00 【bug丸】
常见布局效果实现方案
盒子居中
<body>
<div class="father">
<div class="child"></div>
</div>
</body>
方案1:flex布局
需不需要垂直居中就自己看需求而定,这里主要是水平居中
.father {
width: 100%;
// height: 600px;
background-color: #f5f5f5;
display: flex;
// align-items: center; 垂直(侧轴)方向的居中
justify-content: center;
}
.child {
height: 200px;
width: 200px;
background-color: skyblue;
}
方案2:定位 + tramsform
子绝父相:子盒子相对父盒子向下和向右走父盒子宽度的50%;然后在通过translate返回走自身的50%
.father {
width: 100%;
height: 600px;
background-color: #f5f5f5;
position: relative;
}
.child {
height: 200px;
width: 200px;
background-color: skyblue;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
方案3:定位 + margin
子绝父相:但是top/bottom/left/right都为0;通过margin:auto使其居中
.father {
width: 100%;
height: 600px;
background-color: #f5f5f5;
position: relative;
}
.child {
height: 200px;
width: 200px;
background-color: skyblue;
margin: 0;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
}
左侧固定宽度,右侧自适应
<div class="content">
<div class="left">左边</div>
<div class="right">右边</div>
</div>
方法1:float+overflow
.content {
height: 300px;
width: 100%;
}
.left {
background-color: pink;
height: 100%;
width: 200px;
float: left;
}
.right {
background-color: skyblue;
height: 100%;
overflow: hidden;
}
方法2:float+calc
宽度是通过calc来定,位置通过浮动的特点
.content {
height: 300px;
width: 100%;
}
.left {
background-color: pink;
height: 100%;
width: 200px;
float: left;
}
.right {
background-color: skyblue;
height: 100%;
width: calc(100% - 200px);
float: left;
}
方法3:inline-block + calc
inline-block,两个盒子的宽度刚好为100%,右边calc动态变化宽度
.content {
height: 300px;
width: 100%;
font-size: 0;
}
.left {
background-color: pink;
height: 100%;
width: 200px;
display: inline-block;
vertical-align: top;
}
.right {
background-color: skyblue;
height: 100%;
width: calc(100% - 200px);
display: inline-block;
vertical-align: top;
}
方法4:flex
flex:1 剩下宽度的都分给右边的盒子
.content {
display: flex;
height: 300px;
width: 100%;
}
.left {
height: 100%;
width: 200px;
background-color: pink;
}
.right {
flex: 1;
background-color: skyblue;
}
方法5:position+margin
左边脱离标准流不占位,右边宽度正好利用块级盒子的特点,margin不仅让盒子流出左边空白,宽度页刚好减去了margin值
.content {
height: 300px;
width: 100%;
position: relative;
}
.left {
background-color: pink;
height: 100%;
width: 200px;
position: absolute;
}
.right {
background-color: skyblue;
height: 100%;
margin-left: 200px;
}
边栏推荐
- 电商项目——商城限时秒杀功能系统
- 互换性测量与技术——偏差与公差的计算,公差图的绘制,配合与公差等级的选择方法
- Is Redis old?Performance comparison between Redis and Dragonfly
- A brief analysis of whether programmatic futures trading or manual order is better?
- QueryDet: Cascading Sparse Query Accelerates Small Object Detection at High Resolution
- The impact of programmatic trading and subjective trading on the profit curve!
- Watch to monitor
- Traversal of DOM tree-----modify styles, select elements, create and delete nodes
- watch监听
- 【FPGA】day19-二进制转换为十进制(BCD码)
猜你喜欢

机器学习中什么是集成学习?

CSDN blog replacement skin

Kubernetes集群搭建Zabbix监控平台

Design and Realization of Employment Management System in Colleges and Universities

The last update time of the tables queried by the two nodes of the rac standby database is inconsistent

音视频开发,为什么要学习FFmpeg?应该怎么入手FFmpeg学习?

多串口RS485工业网关BL110

云平台下ESB产品开发步骤说明

图解LeetCode——640. 求解方程(难度:中等)

JS-DOM element object
随机推荐
The development of the massage chair control panel makes the massage chair simple and intelligent
[DB operation management/development solution] Shanghai Daoning provides you with an integrated development tool to improve the convenience of work - Orange
DOM-DOM tree, a DOM tree has three types of nodes
Leetcode 669. 修剪二叉搜索树
uni-app - 城市选择索引列表 / 通过 A-Z 排序的城市列表(uview 组件库 IndexList 索引列表)
Graphical LeetCode - 640. Solving Equations (Difficulty: Moderate)
E-commerce project - mall time-limited seckill function system
80端口和443端口是什么?有什么区别?
JS-DOM element object
The most unlucky and the luckiest
The "top pillar" slides, and new growth is extremely difficult to shoulder the heavy responsibility. Is Ali "squatting" to jump higher?
C语言之自定义类型------结构体
How to delete statements audit log?
音视频开发,为什么要学习FFmpeg?应该怎么入手FFmpeg学习?
没想到MySQL还会问这些...
pathman_config、pathman_config_params 删除后,如何重建?
LeetCode热题(12.买卖股票的最佳时机)
MongoDB 基础了解(二)
程序化交易与主观交易对盈利曲线的影响!
QueryDet: Cascading Sparse Query Accelerates Small Object Detection at High Resolution