我需要将图片放大,但是我使用 background-url
的等效方法是:
.fakeImg:hover img{
transform: scale(1.1);
}
但我只希望图片在 div
内部增大。
当前状态:
目标:
background-size
而不是scale
来仅更改background-image
。
.box {
width:150px;
height:150px;
margin:50px;
border:2px solid red;
background-image:url("https://picsum.photos/400/400?image=1068");
background-size:100% 100%;
background-position:center;
transition:1s all;
}
.box:hover {
background-size:130% 130%;
}
<div class="box">
</div>
overflow: hidden
。以下是一个示例:
.container {
overflow: hidden;
width: 200px;
height: 200px;
}
.image {
width: 200px;
height: 200px;
background-image: url("https://images.pexels.com/photos/658687/pexels-photo-658687.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
background-size: 200px 200px;
transition: 1s all;
}
.image:hover {
transform: scale(1.1);
}
<div class="container">
<div class="image"></div>
</div>
overflow: hidden
添加到.imgblog
。 - Phix