3 replies [Last post]
friday
Offline
Regular
Last seen: 13 years 15 weeks ago
Joined: 2005-02-05
Posts: 34
Points: 0

I want my background-image to be centered horizontally. It must start at 8px from the top of the browser window.

I tried this:
background-position: 50% 8px;

It's horizontally centered, but doesn't start at 8px from the top of the browser window. What am I doing wrong here?

briski
briski's picture
Offline
Elder
London
Last seen: 9 years 6 weeks ago
London
Timezone: GMT+1
Joined: 2004-02-16
Posts: 1066
Points: 0

a simple question about background-position

Are you repeating it in the y direction? If you are it will repeat up as well as down which if it's a solid colour say will appear as if it's ignoring your y position.

friday
Offline
Regular
Last seen: 13 years 15 weeks ago
Joined: 2005-02-05
Posts: 34
Points: 0

a simple question about background-position

yes I am repeating it in the y direction...

thanks for the help. too bad it cannot be fixed.

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 21 weeks 1 day ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

a simple question about background-position

Not tested.

Use a wrapper div to hold the page.

body {
    height: 100%;
    }

#wrapper {
    position: absolute;
    min-width: 100%;
    min-height: 100%;
    margin-top: 8px;
    background: white url(some.png) 50% 0 repeat-y;
    }

* html #wrapper {
    width: 100%;
    height: 100%;
    }
This should work just fine in Moz, IE/Win, and Opera. IE/Mac may require some extra work, and who knows what Safari will do?

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.