I have an amp-img with layout="responsive" and I need to place some text inside it, or on top of it, if you prefer to say it that way. The amp-img will fill the width of the screen and the height will be determined by amp-img so that the entire image is visible and the aspect ratio is maintained.
Is there a way to do this?
I could place the image in the background, but I would lose the responsive sizing provided by amp-img. I have tried this using a background-size of cover or contain, but I the image always ended up being cropped, either on the right or the bottom.
I also tried placing the text with position:absolute, but can not get the text on top of the image. Here is one attempt, which ends up with the text below the image:
<div style="position:relative">
<amp-img src="/images/@Model.ImageUrl" layout="responsive" width="1920" height="1080" alt=""></amp-img> @* 16 x 9 *@
<div class="clearfix" style="padding-top:25%; padding-bottom:10%; position:absolute; z-index:1">
<div class="mx-auto md-col-9">
<h2 class="tx-g2 tx-center ml-1 mr-1 shadow mb-0" style="{text-transform:uppercase;}">
<amp-fit-text width="400" height="20" layout="responsive" max-font-size="75">
@Html.Raw(Model.Title)
</amp-fit-text>
</h2>
</div>
</div>
</div>
Is there a way to get the image sized correctly and also place text on top of it?
PS. Will someone create a tag for amp-fit-text.