Html 在具有不同分辨率的 <td> 中插入图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17502333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert Image in a <td> with different resolution
提问by user2556079
I have a table with 3 rows and one of that is this one:
我有一个 3 行的表,其中之一是这个:
<tr>
<td>Logo Programma</td>
<td>Giorno</td>
<td>Giorno</td>
<td>Put the image here</td>
</tr>
Now I want to add an image and I have used the tag like this
现在我想添加一个图像,我已经使用了这样的标签
<td><img src="image.jpg" alt=""></td>
The resolution is 788x592 but I don't want to use 788x592 pixels, it will be huge! So I want to keep the proportions but with less resolution.
分辨率是 788x592 但我不想使用 788x592 像素,它会很大!所以我想保持比例但分辨率较低。
回答by Yotam Omer
To keep the proportions of the image while setting a new size do something like this:
要在设置新尺寸时保持图像的比例,请执行以下操作:
<td><img src="image.jpg" alt="" style="width:200px; height:auto;"></td>
This will set the width to 200px
and the height will automatically adjust to keep proportions.. you can also calculate the height that should be and add it as a fixed number.
这会将宽度设置为200px
,高度将自动调整以保持比例。您还可以计算应为的高度并将其添加为固定数字。
回答by Cthulhu
Use height
and width
of img
tag, like that:
使用height
and width
ofimg
标签,像这样:
<img src="image.jpg" width="100" height="200" alt="">
EditIf only one dimension is known, you can omit second measurement and the image will scale
accordingly.
编辑如果只知道一个维度,您可以省略第二次测量,图像将scale
相应地。