Doing a simple parallax effect based on this article. I can't understand why there is a blank space between div
. This forces to adjust with top
, which is not ideal. See code below:
body, html, main {
height:100%;
}
.cd-fixed-bg {
min-height: 100%;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center center;
}
.cd-fixed-bg.cd-bg-1 {
background:Red;
}
.cd-fixed-bg.cd-bg-2 {
background:green;
}
.cd-fixed-bg.cd-bg-3 {
background:blue;
}
.cd-fixed-bg.cd-bg-4 {
background:yellow;
}
.cd-fixed-bg.cd-bg-5{
background:orange;
}
.cd-scrolling-bg {
min-height: 100%;
background: black;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="normalize.css" rel="stylesheet">
<link href="styleSO.css" rel="stylesheet">
</head>
<body>
<main>
<div class="cd-fixed-bg cd-bg-1">
</div>
<div class="cd-scrolling-bg cd-color-2" >
</div>
<div class="cd-fixed-bg cd-bg-4">
<h1></h1>
</div>
<div class="cd-fixed-bg cd-bg-5">
<h1></h1>
</div>
<div class="cd-fixed-bg cd-bg-2">
<h1></h1>
</div>
</main>
</body>
</html>
As you can see, I am forced to do stuff like top:-73px;
so there is no gap between div
. I've tried with margin-top
but it was not successful.