Сначала примените position: relative
к тегу body , так как он является предком вашего фона фонового изображения.
Затем установите высоту .background-image
до 100vh
.Это сделает его высотой окна, но это не всегда будет видно.
/* Since the body element is the parent of the .background-image, we need to set its position to relative */
body {
position: relative;
}
.background-image {
position: absolute;
width: 100%;
height: 100vh; /* be exactly the height of the viewport, no bigger */
top: 0;
left: 0;
background-image: url('http://alexismorin.com/images/watertown.jpg');
z-index: -1;
background-position: center;
background-size: cover;
background-attachment: fixed;
}
p {
color: #333;
}
<div class="background-image"></div>
<div>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p><p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p><p>
Site is here
</p><p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
<p>
Site is here
</p>
</div>