We have the following code on codepen. The problem we have is that we are using the <picture> attribute to render images based on viewport, but are not able to have the image take up the same amount of space as the text that is overlaid on image.
codepin details:
- currently the text has
background-color: #eeeso you can see the area the text takes up. - Image and text have
position: absolute, but open to change it. - based on the
viewport, we always want the image from the<source>tag to only take up what the text takes up.
Goal:
- make image take up the same height and width as the text overlaid on top
- use
<picture>and<source> - not use
style: background-image('path/to/image')on<div class="item__img"> - open to cropping image to make it fit, but would prefer it be done without the cropping.
How can we have the image expand as the text on top of it expands?


If your image is always bigger than the textbox, here's a solution