【发布时间】:2022-03-14 21:39:51
【问题描述】:
我有一个 600x400 像素的图像,并希望将其放在一个 240x200 像素的较小 div 中,但图像会缩小或变形。我希望原始大小的图像以较小的 div 为中心,这会隐藏一些图像
我编写了这个 CSS 规则以适用于不同的图像尺寸。
.theBox {
float: left;
overflow: hidden;
width: 240px;
height: 200px;
}
.theBox img {
display: block;
height:100% !important;
width:100% !important;
}
【问题讨论】:
-
我要问,你为什么不使用像 GIMP 或 PhotoShop 这样的程序来调整图像的大小,这样你就不用担心失真等问题了?
-
因为我不想创建很多缩略图,所以这个 div 上显示的图像是指向主要文章的链接。
标签: image css css-transforms