gpt4 book ai didi

html - CSS 图像缩放和悬停居中

转载 作者:太空宇宙 更新时间:2023-11-04 07:30:09 25 4
gpt4 key购买 nike

可以仅使用 CSS 缩放图像并将其居中吗?

例如:

enter image description here

下面的代码只会缩放:

JSFiddle:https://jsfiddle.net/6r0bx6ba/1/

.floatl {
float: left;
}

.main {
width: 100%;
}

.submain {
width: 30%;
float: left;
}

.zoomin img {
width: 200px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}

.zoomin img:hover {
width: 300px;
}
<div class="main">
<div class="zoomin submain">
<img src="https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" title="All you need to know about CSS Transitions " />
</div>
<div class="zoomin submain">
<img src="https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" title="All you need to know about CSS Transitions " />
</div>
<div class="zoomin submain">
<img src="https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" title="All you need to know about CSS Transitions " />
</div>
</div>

最佳答案

悬停在图片上时添加什么:
例如第一个(我添加类来计算 img)

margin-left:70px;
margin-top:70px;

.floatl {
float: left;
}

.main {
width: 100%;
}

.submain {
width: 30%;
float: left;
}

.zoomin img {
width: 200px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}


.a img:hover{
margin-left:100px;
margin-top:70px;}
.b img:hover{

margin-top:70px;}

.c img:hover{
margin-left:-70px;
margin-top:70px;}
<div class="main">
<div class="zoomin submain a">
<img src="https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" title="All you need to know about CSS Transitions " />
</div>
<div class="zoomin submain b">
<img src="https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" title="All you need to know about CSS Transitions " />
</div>
<div class="zoomin submain c">
<img src="https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" title="All you need to know about CSS Transitions " />
</div>
</div>

关于html - CSS 图像缩放和悬停居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49488582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com