.fd_container{ width:100%; height:400px; background:whitesmoke; justify-content: center; align-items: center; display:flex; } .food{ flex:1; overflow: hidden; transition: 0.5s; margin:0 20px; box-shadow: 10px 10px 20px rgba(0,0,0,0.5); border-radius: 10px; border:10px solid #fff; } .food>img{ width:200%; height:85%; object-fit: cover; transition: 0.5s; } .food:hover{ flex-basis: 40%;/*指定flex元素在主轴方向上的大小*/ } .food:hover>img{ width:100%; height:100%; }
时间: 2023-12-06 11:45:23 浏览: 37
这是一个使用 CSS 实现的简单的图片放大效果,通过设置一个容器的宽度和高度以及背景颜色,并将内部的图片包裹在一个拥有溢出隐藏和过渡效果的元素中,通过设置鼠标悬停时容器的大小以及内部图片的大小来实现放大效果。具体实现可以参考以下代码:
```html
<div class="fd_container">
<div class="food">
<img src="example.jpg" alt="example">
</div>
<div class="food">
<img src="example.jpg" alt="example">
</div>
<div class="food">
<img src="example.jpg" alt="example">
</div>
</div>
```
```css
.fd_container{
width:100%;
height:400px;
background:whitesmoke;
justify-content: center;
align-items: center;
display:flex;
}
.food{
flex:1;
overflow: hidden;
transition: 0.5s;
margin:0 20px;
box-shadow: 10px 10px 20px rgba(0,0,0,0.5);
border-radius: 10px;
border:10px solid #fff;
}
.food > img{
width:200%;
height:85%;
object-fit: cover;
transition: 0.5s;
}
.food:hover{
flex-basis: 40%;/*指定flex元素在主轴方向上的大小*/
}
.food:hover > img{
width:100%;
height:100%;
}
```