我有一个带有标题的图像,就像这样:
<figure> <img src="image.jpg"/> <figcaption>标题</figcaption> </figure>
我在CSS中还有img{max-width:100%}。
我想同时设置图像的宽度和高度,并在宽度减小到其设置值以下时保持其纵横比。所以,我尝试了这样的代码:
<figure> <img src="image.jpg" width="100" height="200" style="object-fit:contain"/> <figcaption>标题</figcaption> </figure>
这大致是我想要的,但是当图像被'letterboxed'时,标题离图像底部的距离很远。
有没有办法在保持标题紧贴图像底部的同时获得我想要的结果?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号