flex布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 800px;
height: 400px;
background-color: pink;
margin: 0 auto;
/*以下三行代码 盒子居中*/
/* 弹性容器 默认在一排排列 */
display: flex;
/* 主轴 默认x轴 居中 */
justify-content: center;
/*侧轴 y轴 居中 */
align-items: center;
}
/* 弹性盒子 */
div {
width: 200px;
height: 400px;
background-color: aqua;
}
</style>
</head>
<body>
<div class="box">
<div></div>
</div>
</body>
</html>
圣杯布局 移动端常用布局方式之一
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
width: 100%;
height: 50px;
background-color: pink;
display: flex;
}
.box .left,
.box .right {
width: 50px;
height: 50px;
background-color: aqua;
}
.box .center {
/* 伸缩比 */
flex: 1;
height: 50px;
background-color: greenyellow;
}
/* 注意:
1设置伸缩比之后 伸缩比生效 宽度不生效
2 伸缩比给子元素设置
3伸缩比占的位置是父元素的位置 */
</style>
</head>
<body>
<div class="box">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
</body>
</html>
你学废了吗?