Can anyone help me figure out how to fill a div
's background with an image, regardless of its aspect ratio (landscape or portrait)? I've tried different methods from using background-size: cover;
to background-size: 100% 100%;
, but the div doesn't always get completely filled. The div itself has a landscape width/height ratio while the images have random ratios. When I apply background-size: cover;
, the landscape images fit perfectly, but the portrait ones leave gaps on the sides.
Edit:
div {
background: url(img.png) no-repeat center center;
background-size: cover;
height: 100%;
width: 100%;
}