bleevo
bleevo

Reputation: 1667

How can I center a background using a CSS element?

How can I center a background using a CSS element?

Upvotes: 2

Views: 3607

Answers (2)

Mr Snuffle
Mr Snuffle

Reputation: 654

background-position:center;

https://developer.mozilla.org/en/CSS/background-position

Upvotes: 10

paulb
paulb

Reputation: 784

You can also use percentages, so

background-position: 50% 0;

would centre the background horizontally. The beauty of percentages is they offers greater flexibility than keywords. You can position a background a quarter of the way across the screen with,

background-position: 25% 0;

and a quarter of the way across and 3 quarters of the way down with,

background-position: 25% 75%;

Upvotes: 5

Related Questions