自动缩放图像以匹配文本高度 [英] Automatically scale an image to match text height

查看:55
本文介绍了自动缩放图像以匹配文本高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像,我想在其中插入一些文字,但是我需要它以匹配文字高度.我知道有可能使用<img src="img.jpg" height=16>甚至<img src="img.jpg" height="100%">之类的东西,但是前者不能随文本大小缩放,而后者似乎可以使其达到div的大小,而不是文本高度.有人可以帮忙吗?

I've got an image which I want to use inline with some text, but I need it to match the text height. I know it's possible to something like <img src="img.jpg" height=16> or even <img src="img.jpg" height="100%">, but the former does not scale with text size and the latter seems to make it the size of the div, not the text height. Can anyone help?

HTML示例:

<body>
This is a test <img src="img.jpg">
</body>

推荐答案

您是否尝试过将图像高度设置为1em?

img {height: 1em;}

这篇关于自动缩放图像以匹配文本高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆