Keep background image fixed during scroll using css

Css

Css Problem Overview


How do I keep the background image fixed during a page scroll? I have this CSS code, and the image is a background of the body and not <div></div>

body {
  background-position:center;
  background-image:url(../images/images5.jpg);
}

Css Solutions


Solution 1 - Css

Solution 2 - Css

background-image: url("/your-dir/your_image.jpg");
min-height: 100%;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: cover;}

Solution 3 - Css

Just add background-attachment to your code

body {
    background-position: center;
    background-image: url(../images/images5.jpg);
    background-attachment: fixed;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionX10nDView Question on Stackoverflow
Solution 1 - CssQuentinView Answer on Stackoverflow
Solution 2 - CssChris WalterView Answer on Stackoverflow
Solution 3 - CssOmar MasryView Answer on Stackoverflow