Reputation: 13051
i need to put an image in background of a div at the center position of it, like:
What i've tried is:
<div id="container">
...
</div
<div id="background">
<img src="images/bg.png"/>
</div>
with this css:
div#container {
margin: 0 auto;
width: 52em;
}
div#bg img {
z-index: -999;
width: 100%;
height: 100%;
position: absolute;
top: 22%;
}
In my browser, with my screen size, i put 22% and all is ok, but if i try on another screen with different size background img isn't in the center of div. What can i do? can someonehelp me?
Upvotes: 0
Views: 3535
Reputation: 2703
Give
position:relative;
in the container div..It should work..
And the background div(with position:absolute;
) should be a child of container div..then only u'll get the div overlapping property
Upvotes: 3
Reputation: 1844
can use css as below:
#sample
{
background:url(bg_apple_little.gif) no-repeat center center;
height:200px;
width:200px;
}
& you div would be with id="sample". height, width can be varied as per your requirement.
Upvotes: 0