Satch3000
Satch3000

Reputation: 49422

CSS background image on DIV's vertical center

I have a div and I need to get a small background image into the vertical center of that DIV using CSS.

Can anyone help please?

Thanks.

Upvotes: 31

Views: 46910

Answers (2)

sandeep
sandeep

Reputation: 92853

To vertically center:

#con {
    background: url(image.jpg) no-repeat left center;
}

To horizontally center:

#con {
    background: url(image.jpg) no-repeat center top;
}

Upvotes: 50

clairesuzy
clairesuzy

Reputation: 27664

#somediv {
background: url (image.jpg) no-repeat 50% 50%;
}

the 50% centers it horizontally and vertically.. alternatively you can use center center

Upvotes: 11

Related Questions