简体   繁体   English

HTML-按高度将图像拟合到表格单元格

[英]HTML - fitting an image to a table cell by height

OK guys, I need some help... 好的,我需要一些帮助...

I have a table cell which I need to fill with an image I get from an url. 我有一个表格单元格,我需要填写从URL获得的图像。 The image width/height ratio is different than the one of the table cell - the image is longer than the cell. 图像的宽/高比与表格单元格之一不同-图像比单元格长。 I need to fit it in with 100% height, and trim the left and right ends so it fits by width. 我需要将其调整为100%的高度,并修剪左右两端,以使其适合宽度。

I am new to the website so I can't post pics of examples, but I hope I made myself clear as to what is the problem... 我是该网站的新手,所以我无法发布示例图片,但我希望我明确指出了问题所在...

Any help would be highly appreciated... 任何帮助将不胜感激...

The easiest solution would be to set it as a background image for the table cell, it will get cropped visually automatically. 最简单的解决方案是将其设置为表格单元的背景图像,它将在视觉上自动进行裁剪。

If you want to resize that background image so that it completely covers the table cell, while maintaining its aspect ration, you can use the css3 property (limited browser support, IE...): 如果要调整背景图像的大小以使其完全覆盖表格单元格,同时保持其纵横比,则可以使用css3属性(有限的浏览器支持,IE ...):

background-size: cover;

The complete code: 完整的代码:

background: url(/url/to/image) no-repeat center center;
background-size: cover;     // just for modern browsers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM