Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust image size based on the font size

Tags:

I am putting together an HTML page to be viewed in both mobile phones and PC/Mac. In the text, I sometimes have inline images:

<p>to do that, then press on button <img src="button.png" /> for 2 seconds</p> 

My fonts are sized in em or % so it is readable on both low res-phones and high-res phones. The issue is that my buttons (usually 32px high images) appear so tiny on high-res phones.

How do I adjust the image size? Preferably pure CSS, but JS is still OK.

like image 774
Memes Avatar asked Aug 26 '13 02:08

Memes


People also ask

How do you change the font size of a picture in HTML?

If you set the size of your font in the <p> tag, you should just be able to use height: 1em; on p img to set the image's height to that of the font. And if you want it to be double the size of the font, you'd just set the height of the image to 2em.


1 Answers

If you set the size of your font in the <p> tag, you should just be able to use height: 1em; on p img to set the image's height to that of the font.

Here's a jsfiddle to show what I mean:

body {    font-size: 62.5%;    /*sets 1em to 10px for convenience*/  }    p {    font-size: 3em;  }    p img {    height: 1em;    width: auto;  }
<p>Hello world! <img src="http://images.wikia.com/dragonvale/images/e/e8/Space_invader.jpg"></p>

And if you want it to be double the size of the font, you'd just set the height of the image to 2em.

like image 72
everydayghost Avatar answered Oct 04 '22 04:10

everydayghost