Reputation: 861
In the following snippet I want the body element to have scrollbars, but it doesn't behave as expected. I set the html element to height:100% which gets the height of the Initial Containing Block, and the body is 100% gets the height of the html element. Now I set the overflow: scroll on body to get scrollbars because I don't want the boxes to be visible outside of the body, but they remain in the same place. What am I missing? This is just a test, I am learning and reading the CSS specs to understand how height on html and body works. Thanks.
body {
background-color: red;
height:100%;
overflow: scroll;
}
html {
background-color: yellow;
height: 100%;
}
.box {
width: 300px;
height: 300px;
background-color: blue;
margin-bottom: 20px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</body>
</html>
Upvotes: 0
Views: 816
Reputation: 495
Check the first answer from these question -> why body overflow not working?
You need to add overflow: auto
to your html element.
Heres a pen: https://codepen.io/sebaLinares/pen/NOOdJM
Upvotes: 2