1、上下两行布局=>正好占满全屏=>方法一:用calc。内容超长,会出现滚动条,不会超屏。
```html:run
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
}
.nav {
height: 50px;
background: #BBE8F2;
width: 100%;
}
.body {
height: calc(100% - 60px);
background: #D9C666;
margin-top: 10px;
font-size: 0;
}
.inline {
display: inline-block;
}
.left {
width: 200px;
height: 100%;
overflow: auto;
background: palevioletred;
margin-right: 10px;
font-size: 16px;
}
.right {
width: calc(100% - 210px);
height: 100%;
overflow: auto;
background: rebeccapurple;
font-size: 16px;
}
</style>
</head>
<body>
<div class="nav"></div>
<div class="body">
<div class="inline left">
</div>
<div class="inline right">
</div>
</div>
</body>
</html>
```
2、上下两行布局=>正好占满全屏=>方法二:用flex。内容超长,不会出现滚动条,会超屏。
```html:run
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
}
.full {
display: flex;
flex-direction: column;
}
.nav {
height: 50px;
background: #BBE8F2;
width: 100%;
}
.body {
flex: 1;
background: #D9C666;
font-size: 0;
}
.inline {
display: inline-block;
}
.left {
width: 200px;
height: 100%;
overflow: auto;
background: rebeccapurple;
font-size: 16px;
margin-right: 10px;
}
.right {
width: calc(100% - 210px);
height: 100%;
overflow: auto;
background: rebeccapurple;
font-size: 16px;
}
</style>
</head>
<body class="full">
<div class="nav"></div>
<div class="body">
<div class="inline left">
</div>
<div class="inline right">
</div>
</div>
</body>
</html>
```
3、上下两行布局=>下行用最小高度=>方法一:用min-height。内容超长,会出现滚动条,不会超屏。
```html:run
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>最小高度</title>
<style>
*{
padding: 0;
margin: 0;
}
.nav {
height: 50px;
background: #BBE8F2;
}
.body {
min-height: 500px;
background: #D9C666;
}
p{
height:100px;
}
</style>
</head>
<body>
<div class="nav"></div>
<div class="body"></div>
</body>
</html>
```
4、上下两行布局=>总高度不变,此增彼减=>方法一:用flex。内容超长,不会出现滚动条,会超屏。
```html:run
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
.full {
height: 600px;
background: red;
display: flex;
flex-direction: column;
}
.up {
background: blue;
}
.down {
background: green;
flex: 1; /*height:100%;*/
}
</style>
</head>
<body>
<div class="full">
<div class="up">
<p>ABCD</p>
</div>
<div class="down">
<p>DCBA</p>
</div>
</div>
</body>
</html>
```
转载于:https://www.cnblogs.com/gushixianqiancheng/p/10967029.html