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?
Example HTML:
<body> This is a test <img src="img.jpg"> </body>
Answer: Use the CSS max-width Property You can simply use the CSS max-width property to auto-resize a large image so that it can fit into a smaller width <div> container while maintaining its aspect ratio.
If the Shift key is held down whilst moving the handle, then the proportions of the object will be preserved. For example, if I hold Shift and drag the bottom edge upwards to reduce the size by half, then the right edge will automatically move to the left to reduce the width of the object by the same amount.
One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels. For example, the original image is 640×960.
img {height: 1em;}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With