效果图
面试官说请实现一个两边等宽中级自适应的布局
代码
通过给子元素设置flex-grow属性,可以按比例分配父元素宽度
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
.header,
.footer {
height: 50px;
background: green;
}
.main {
display: flex;
flex-direction: row;
justify-content: space-between;
height: calc(100% - 100px);
}
.left {
/* flex-grow: 1; */
width: 100px;
background-color: red;
}
.mid {
flex-grow: 1;
background-color: chartreuse;
}
.right {
/* flex-grow: 1; */
width: 100px;
background-color: blueviolet;
}
</style>
</head>
<body>
<div class="header">header</div>
<div class="main">
<div class="left">left</div>
<div class="mid">mid</div>
<div class="right">right</div>
</div>
<div class="footer">footer</div>
</body>
</html>
思考
如何让mid块优先加载???