[英]How to make a second div fill the remaining height of the screen without scrollbar?
我有2個div:第一個div具有100px的高度,第二個我想填充屏幕的其余部分而沒有垂直滾動條。 我試圖將第二個divs高度設置為100%,但是出現了滾動條。
<html>
<body>
<div class="wihe100">
<div class="firstDiv">
AAA
</div>
<div class="wihe100 redBack">
BBB
</div>
</div>
</body>
</html>
html, body
{
height:100%;
margin: 0px;
}
.wihe100
{
width: 100%;
height: 100%;
}
.redBack
{
background-color: #FF0000;
}
.firstDiv
{
height: 100px;
background-color: #0000FF;
}
這是一個JSFiddle: http : //jsfiddle.net/wHtX7/1/
選項1:為主體本身提供紅色背景。
html, body{
height:100%;
margin: 0px;
background-color: #FF0000;
}
.firstDiv{
height: 100px;
background-color: #0000FF;
}
選項2:將redBack
高度設置為100% redBack
。
HTML:
<div class="wihe100">
<div class="firstDiv">AAA</div>
<div class="redBack">BBB</div>
</div>
CSS:
html, body {
margin: 0px;
}
html, body,.wihe100 {
height:100%;
}
.redBack {
background-color: #FF0000;
height:calc(100% - 100px);
}
.firstDiv {
height: 100px;
background-color: #0000FF;
}
您可以設置overflow: hidden;
在包含兩個DIV的父DIV <div class="wihe100">
中。
這是一個工作的小提琴
使用flexbox
<html>
<body>
<div class="wihe100">
<div class="firstDiv">
AAA
</div>
<div class="wihe100 redBack">
BBB
</div>
</div>
</body>
</html>
-
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
.wihe100 {
display: flex;
height: 100vh;
flex-direction: column;
}
.firstDiv {
background-color: red;
height: 100px;
}
.redBack {
background-color: blue;
flex: 1;
}
我認為通過添加
overflow-y:hidden;
對您的.wihe100類將有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.