【问题标题】:Fitting image in the column of a table在表格的列中拟合图像
【发布时间】:2016-03-17 23:27:17
【问题描述】:

我需要我的图像宽度为 20%,高度为 20%,但是当我使用 20% 的宽度时,它会将列的宽度拉伸到右侧有很多空白的地方图片。我不想要额外的空格。我该如何解决?

img {
width: 20%;
height: 20%;	
}
<table border = '1'>
	
<tr>
<td> <img src = "http://www.thetimes.co.uk/tto/multimedia/archive/00309/108787995_309592c.jpg" height="42" width="42"> </td>
<td> This is a cat! </td>	
</tr>	
	
</table>

【问题讨论】:

  • 首先,去掉img标签中的height="42" width="42"。另外,您的表格宽度在哪里定义?

标签: html css image html-table


【解决方案1】:

不完全确定你在追求什么,但摆脱内联的高度和宽度属性和宽度 css 属性应该可以解决它。

img {
    height: 20%;	
}
<table border = '1'>
	
<tr>
<td> <img src = "http://www.thetimes.co.uk/tto/multimedia/archive/00309/108787995_309592c.jpg"> </td>
<td> This is a cat! </td>	
</tr>	
	
</table>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 2010-10-08
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多