是什么导致垂直滚动栏出现在这里?http://codepen.io/anon/pen/qgbyoq?editors=1100
我建议的是,.container
是100%
body
的高度,身体继承html
,html
是viewport
的100%,因此每个.chart
都应该非常适合,因为它的高度是.container
的一半。然而,出现了Y-Scrollbar。这背后的行为是什么?
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div class="container">
<div class="chart1"></div>
<div class="chart1"></div>
<div class="chart1"></div>
<div class="chart1"></div>
</div>
</body>
</html>
CSS:
.container {
width: 100%;
height: 100%;
border: 5px dashed black;
box-sizing: border-box;
font-size: 0;
overflow: auto;
}
html, body {
height: 100%;
}
body {
margin: 0;
}
.chart1 {
display: inline-block;
width: 50%;
height: 50%;
border: 1px solid red;
box-sizing: border-box;
}
这是由于容器的红色边框造成的。使用CSS calc()
功能,例如:
.chart1 {
height: calc(100% - 1px); /* 1px for the extra border */
}
请查看下面的片段:
.container {
width: 100%;
height: 100%;
border: 5px dashed black;
box-sizing: border-box;
font-size: 0;
overflow: auto;
}
html, body {
height: 100%;
}
body {
margin: 0;
}
.chart1 {
display: inline-block;
width: 50%;
height: calc(50% - 1px);
border: 1px solid red;
box-sizing: border-box;
}
<div class="container">
<div class="chart1"></div>
<div class="chart1"></div>
<div class="chart1"></div>
<div class="chart1"></div>
</div>
希望这会有所帮助!