It is well known that using max-height and max-width can make an image auto fit in a div, like the following:
.cover img {
max-width: 100%;
max-height: 100%;
}
Is there a way to make a translucent cover (by setting opacity: 0.8
to a div) that just fit the size of the image without getting the width and height by javascript?
The following is my attempt in jsfiddle. I can only make it cover the whole container, but what I want is just to cover the image only. The size of the image is variable as they are to be uploaded by user. https://jsfiddle.net/muorou0c/1/