我有一张尺寸为600x400像素的图片,想将其放入一个尺寸为240x200像素的小div中,但是图片会缩小或变形。我希望原始尺寸的图片居中显示在小div中,这样就可以隐藏部分图片。
我编写了以下CSS规则来适用于不同大小的图片。
.theBox {
float: left;
overflow: hidden;
width: 240px;
height: 200px;
}
.theBox img {
display: block;
height:100% !important;
width:100% !important;
}