Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to vertically align a background image that has background-size: cover?

Tags:

css

I have a div with a background image with background-size: cover. Is that possible to vertically align the background image on center?

I tried background-position: left center e background-position: 0 50%

here is a fiddle http://jsfiddle.net/V8X2V/

EDIT:

Indeed background-position: left center; works! my problem was that I had a inline style for background, and was trying to add the background-position in a css file, for some reason it wouldn't work. But when I did put the position inline, it worked...

like image 983
igrossiter Avatar asked Oct 22 '25 13:10

igrossiter


1 Answers

You can use background-position. Something like this :

div {
    background: url(http://placekitten.com/400/400);
    background-size: cover;
    width: 300px;
    height: 150px;
    background-position: 0% 30%;
}

DEMO : JSFIDDLE

like image 195
Farzad Avatar answered Oct 25 '25 06:10

Farzad