I have a div with a background image that is always supposed to have the same aspect ratio no matter the screen resolution. I set this with:
padding-top: 50%;
Now, inside that div I am trying to center (equal top and bottom, left and right) an image, also no matter what the resolution. I achieve this with:
left: 50%;
display: inline-block;
transform: translate(-50%,0);
position: absolute;
z-index: 1;
top:50px;
Now, that all works, except the image is not centered vertically as the browser resizes. It moves up and down.
How do I achieve it to align vertically
in the middle
as well? I suspect I have to remove the top:50px
but then I am stuck on how to center it..
Here is a fiddle: https://jsfiddle.net/fjLo7egd/1/