I am trying to build a card that has a background image, that when clicked, darkens that background image and then displays a lighter, transparent div with text on top of it. Both the darkening of the background card, and the appearance of the text div need to have transitions.
I have managed to create this functionality, including transitions, using a container with relative positioning, that contains an image with absolute positioning: https://jsfiddle.net/marcuslv/kmbvxt14/
The issue with this solution is that I can't work out how to scale the image inside the container such that when it grows and shrinks, it adapts its size to the container.
I want it to behave like a css background-image if it had these properties:
background-image: url('https://www.fillmurray.com/300/300');
background-size: contain;
background-repeat: no-repeat;
background-position: center top;
I have implemented a near equivalent solution using a css background-image instead of an img element as in the first fiddle: https://jsfiddle.net/marcuslv/knq3e7dg/
The issue with this solution is that I can't get the background image to transition to its darkened state - it transitions immediately which is a bit jarring - and more importantly, I will be using b64 images for this project, which are finicky to set as a css background-image and I would much prefer to use an img element.