css - How to set a background image in full size of a div that doesn't fill page -


i need put image in background of div @ center position of it, like: example

what i've tried is:

<div id="container"> ... </div <div id="background"> <img src="images/bg.png"/> </div> 

with css:

div#container { margin: 0 auto; width: 52em; } div#bg img { z-index: -999; width: 100%; height: 100%; position: absolute; top: 22%; } 

in browser, screen size, put 22% , ok, if try on screen different size background img isn't in center of div. can do? can someonehelp me?

give

position:relative; 

in container div..it should work.. , background div(with position:absolute;) should child of container div..then u'll div overlapping property


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -