Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I center a background using a CSS element?

Tags:

css

How can I center a background using a CSS element?

like image 889
bleevo Avatar asked Feb 21 '26 23:02

bleevo


2 Answers

background-position:center;

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

like image 192
Mr Snuffle Avatar answered Feb 23 '26 15:02

Mr Snuffle


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%;
like image 20
paulb Avatar answered Feb 23 '26 16:02

paulb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!