提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
最近在公司中使用到一个场景,一个父元素高度固定,俩个子元素高度随另一个子元素高度变化而。写这篇文章主要是为了保存这个模板。
参考博客:跳转地址
一、效果
二、代码
代码如下(示例):
<!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>
body {
margin: 0;
padding: 0;
}
.outer {
display: flex;
flex-direction: column;
height: 100vh;
background-color: red;
}
.head {
flex-shrink: 0;
background-color: rgb(244, 180, 16);
}
.content {
flex: auto;
background-color: rgb(176, 180, 177);
overflow: auto;
}
</style>
</head>
<body>
<div class="outer">
<div class="head">
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Eligendi
necessitatibus non ipsum alias deleniti libero sint officia, provident
</div>
<div class="content">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum nam
tempore officia dolor consequatur quas ea odio doloremque. Id nulla
reiciendis rerum voluptates laborum excepturi quas nam ipsa consequatur
quaerat tenetur doloribus iusto, nam earum quod sed nihil, aliquid
cupiditate ea placeat cumque recusandae vel! Quas eius quidem doloribus
illum natus accusantium distinctio corrupti voluptatibus optio aut
earum, aliquid eligendi perferendis! Porro tempore eos sequi debitis,
minus ex explicabo, repellendus eius nesciunt ut, eum sapiente id
dolores repellat iure ipsam vel assumenda fugiat voluptates incidunt.
Similique molestias, necessitatibus asperiores nisi voluptates
voluptatem mollitia, aliquam sapiente maxime repellat eius minus quidem
numquam possimus? Perferendis possimus officia voluptatem libero.
</div>
</div>
</body>
</html>
总结
如有更好的布局方式,欢迎留言分享。