Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain what "background: url(images/bg.jpg) no-repeat center center;" is doing?

Tags:

css

I've been using this method

http://css-tricks.com/perfect-full-page-background-image/

With this as my css for the div.

    mydiv {
            background: url(images/bg.jpg) no-repeat center center; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
    }

I don't understand what this part is. Which css properties is it filling in?

    center center; 

Can anyone enlighten me?

like image 996
eygrr Avatar asked Dec 03 '25 22:12

eygrr


2 Answers

You will understand it better, if you split your background properties into:

background-image:url('images/bg.jpg');
background-repeat:no-repeat;
background-position:center center;
like image 158
MillaresRoo Avatar answered Dec 06 '25 13:12

MillaresRoo


no-repeat means the background image will display once.

center center

means that the image will be centered both vertically and horizontally.

like image 31
Fengson Avatar answered Dec 06 '25 14:12

Fengson