0 0 Votes

HTML: Background image of website should not scroll with the rest of the page

Question by Translated Content | 02/06/2012 at 11:11

I would like to have a background image at the top of my homepage, which does not disappear when scrolling down, but almost remains on the top side of the browser.

In other words, the content of the website should be able to scroll over the background away and the image in the background should remain static always standing in the same position.

Is there a way to do that somehow?

ReplyPositiveNegative

Stefan Trost

Show Profile | Message
Avatar
1Best Answer
1 Vote

Just use the following CSS to implement your plan:

body {
   background-image: url("background.jpg");
   background-repeat: repeat-x;
   background-attachment: fixed;
}

The property "fixed" provides the effect that you want. The "repeat-x" is favorable at this point, if you have an image that should be repeated across the top of the page from left to right (for example, a shadow or something similar). If you would like to have only one image without repetition, you have to omit the "repeat-x" or you can use another "background-repeat".

Example: the website sttmedia.com is using exactly the code above with "repeat-x" and "fixed". There, you can see how this is looking like.
03/06/2012 at 04:40

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.