Reputation: 855
What causes vertical scrollbar to appear here? http://codepen.io/anon/pen/QGByOQ?editors=1100
As I suggest, .container
is 100%
height of body
, body inherits html
, html
is 100% of the viewport
, hence every .chart
should fit perfectly as it's height is half of the .container
's. Nevertheless a y-scrollbar appears. What's the behavior behind this?
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;
}
Upvotes: 3
Views: 2803
Reputation: 9731
This is due to the red border of the container. Use CSS calc()
function, like:
.chart1 {
height: calc(100% - 1px); /* 1px for the extra border */
}
Have a look at the snippet below:
.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>
Hope this helps!
Upvotes: 5