You can use background-size: coverfor that, but this will result in the top and/or bottom part of the image being cut off in the situation you are showing in your screenshot (also depending on the background-position setting).
It depends on the image and on the screen proportions (width versus height of the area in which the image is shown) whether that works well – you’ll have to try.
The best thing would be to set the height relative to the width so you always get the same width/heigth ratio, using vw units for it.
2
Answers
You are all right there. Just need to replace
background-size: contain;
widthbackground-size: cover;
.Even if that does not make, then you can try aspect ratio.
Hope this helps.
You can use
background-size: cover
for that, but this will result in the top and/or bottom part of the image being cut off in the situation you are showing in your screenshot (also depending on thebackground-position
setting).It depends on the image and on the screen proportions (width versus height of the area in which the image is shown) whether that works well – you’ll have to try.
The best thing would be to set the height relative to the width so you always get the same width/heigth ratio, using
vw
units for it.