Article Directory
1. Topic
Give your answer based on the question.
(The lower height is fixed, the upper adaptive)
Title: The lower height is fixed at 150px, and the upper adaptive.
Second, my code details
https://codepen.io/janmie-cjm/pen/LYNBqrz
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>页面布局-两栏布局4</title>
<style>
html *{
margin: 0;
padding: 0;
}
body{
background: #ffccee;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<!-- 下高度固定150px,上自适应 -->
<!-- 1-绝对定位 -->
<!-- <section>
<style>
.top1 {
background: #aee;
width: 100%;
height: 100%;
position: absolute;
}
.bottom1 {
background: #eaa;
width: 100%;
height: 150px;
position: absolute;
bottom: 0;
}
</style>
<article class="wrapper1">
<div class="top1">我是上栏</div>
<div class="bottom1">我是下栏</div>
</article>
</section> -->
<!-- 2-flexbox -->
<!-- <section class="wrapper2">
<style>
body,section,article {
display: flex;
flex-direction: column;
width: 100%;
height: 100vh;
}
.top2 {
background: #aee;
width: 100%;
flex: 1;
}
.bottom2 {
background: #eaa;
width: 100%;
height:150px;
}
</style>
<article>
<div class="top2">我是上栏</div>
<div class="bottom2">我是下栏</div>
</article>
</section> -->
<!-- 3-table -->
<!-- <section>
<style>
.wrapper3 {
display: table;
width: 100%;
height: 100vh;
}
.wrapper3>div {
display: table-row;
}
.top3 {
background: #aee;
width: 100%;
}
.bottom3 {
background: #eaa;
width: 100%;
height: 150px;
}
</style>
<article class="wrapper3">
<div class="top3">我是上栏</div>
<div class="bottom3">我是下栏</div>
</article>
</section> -->
<!-- 4-grid -->
<section>
<style>
.wrapper4 {
display: grid;
grid-template-columns: auto;
grid-template-rows: auto 150px;
width: 100%;
height: 100vh;
}
.top4 {
background: #aee;
width: 100%;
}
.bottom4 {
background: #eaa;
width: 100%;
}
</style>
<article class="wrapper4">
<div class="top4">我是上栏</div>
<div class="bottom4">我是下栏</div>
</article>
</section>
</body>
</html>
Three, summary
-
What are the solutions to this problem?
Absolute positioning / flexbox / table layout / grid layout; -
The advantages and disadvantages of each program?
1) Absolute positioning
Excellent: Simple Shortage : Break
away from the document flow, need to combine with BFC application, more code
2) Excellent flexbox
: Simple and fast, good compatibility
3) Table layout
Excellent: Good compatibility Shortage : The
height of each column will change at the same time ; The table needs to be rendered first, and the page generation speed is delayed.
4) Grid layout.
Excellent: It can realize the two-dimensional complex operation with multiple rows and multiple columns, with better compatibility and simplified code -
Are there any compatible solutions?
flexbox, grid layout
note! ! ! The up and down layout spreads the entire page, generally the outermost height is set to height = 100vh.
*There are still many shortcomings in the code. We hope to put forward different opinions and communicate with each other. *