CSS image positioning

I have a responsive website with a large background image.  When you resize the page, the background image adjusts as it should.  However, It stays flush left.  I want the image to always stay centered on the page, so I see the middle of the image, always.  How do I accomplish this?
LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russ SuterSenior Software DeveloperCommented:
body { 
    background-image: url('smiley.gif');
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center; 
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
@russ, can I also use that to position the image about 8% higher?
Russ SuterSenior Software DeveloperCommented:
You can specify a fixed position for an image as follows:

background-position: bottom 50px; /* position image 50 pixels from the bottom */

You can also specify a relative position like this:

background-position: right 50% top 42%;

You can also use the calc() syntax as long as your browser supports it (which all current major ones do)

background-position: calc(80% - 20px);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.