Reputation: 2813
When I resize my window the background image also moves and gets resized, I dont want it to get resize, i want it to remain static. I am really confused how to keep my background static. If I set the width in pixels, then it remains static but that wont be good option as depending on different screen sizes
body {
background-color: #000000;
margin: 0 auto;
width: 100%;
}
#container {
background: url("url") no-repeat scroll center top transparent;
width: 100%;
}
The code is like:
<body>
<div id="container">
</div>
</body>
Upvotes: 3
Views: 14770
Reputation: 2660
did you try this?
#container {
background: url("url");
background-repeat:no-repeat;
background-position:fixed;
}
Upvotes: 1
Reputation: 103
Try this code -
#container {
background: transparent url("url") 0 0 no-repeat;
width: 100%;
}
Upvotes: 1
Reputation: 50189
If you set the image to be width:100%
then the image will resize with the screen. If you want it to just sit on the top center without scaling then you can use position:fixed
, explicit width
and then position it correctly.
#container {
background:url("url") no-repeat scroll center top transparent;
background-position:fixed;
position:fixed;
width:500px; /* width of image */
height:auto;
top:0;
left:50%;
margin-left:-250px; /* -1/2 width */
}
Upvotes: 0