Search code examples
javascriptjqueryhtmlcssbackground-image

Vertically center background image


I am trying to vertically center my background in a div. I made a schema for a better comprehension:

This is what i have for now :

enter image description here

The only problem as you can see, is that the image is taller than the div.

I don't want to resize the image, but just want to the image to be centered within the div.

I have made a second image to explain : enter image description here

I tried vertical-align:center but it didn't work either.

I can't post the jsfiddle because i havn't the reputation to post more than two link... I post it on the comment.


Solution

  • Try doing this background-attachment : absolute;

    OR

    Simply remove this code background-attachment : fixed;