简体   繁体   English

CSS Hover:缩小图像框+缩放图像

[英]CSS Hover: Reduce image box + zoom image

I hope someone can help me.我希望有一个人可以帮助我。 I want to animate an image with a hover effect using Wordpress.我想使用 Wordpress 为具有 hover 效果的图像制作动画。 If you move the mouse over the image, the image should enlarge, but the image box should decrease at the same time.如果将鼠标移到图像上,图像会放大,但图像框会同时缩小。

Here is an example of how I imagine it:这是我想象的一个例子:

https://solene.qodeinteractive.com/ (If you scroll down to Authentic Photos) https://solene.qodeinteractive.com/ (如果您向下滚动到真实照片)

So far I have placed the image in wordpress and inserted the following code in custom css:到目前为止,我已将图像放入 wordpress 并在自定义 css 中插入以下代码:

.elementor-5528 .elementor-element.elementor-element-e19f93f .elementor-image img:hover {
   width: 100%;
   height: auto;
   -webkit-transform: scale (1.3);
   transform: scale (1.2);
   -webkit-transition: all 0.7s ease;
   transition: all 0.7s ease;
}

However, the image including the image box is now enlarged.但是,包含图像框的图像现在被放大了。 What else do I have to add so that the image box does not increase in size with the image, but rather decreases in size?我还需要添加什么才能使图像框的大小不会随图像增加,而是减小? I would be very grateful if someone can help me.如果有人可以帮助我,我将不胜感激。

Best regards, Julia最好的问候, Julia

On hover we crop the size of the parent container and at the same time we scale a child image.在 hover 上,我们裁剪父容器的大小,同时缩放子图像。 That's it.而已。

Please, check this at codepen:请在 codepen 上查看:

css css

div {
  max-width: 300px;
  transition: all ease 0.5s;
  clip-path: inset(0 0 0 0);
}
img {
  display: block;
  width: 100%;
  transition: transform ease 0.5s;
}
div:hover {
  clip-path: inset(12px 12px 12px 12px);
}
div:hover img {
  transform: scale(1.05);
}

html: html:

<div>
  <img alt="image" src="https://solene.qodeinteractive.com/wp-content/uploads/2019/11/h1-port-feauture-img-2.jpg"/>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM