X10nD
X10nD

Reputation: 22030

Keep background image fixed during scroll using css

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);
}

Upvotes: 72

Views: 164072

Answers (3)

Omar Masry
Omar Masry

Reputation: 19

Just add background-attachment to your code

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

Upvotes: 1

Chris Walter
Chris Walter

Reputation: 317

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

Upvotes: 20

Quentin
Quentin

Reputation: 943108

background-attachment: fixed;

http://www.w3.org/TR/CSS21/colors.html#background-properties

Upvotes: 151

Related Questions