简体   繁体   English

如何在不改变大小的情况下“缩放”图像 CSS

[英]How can "scale" an image without changing the size CSS

 #image{ background:red } #image:hover { transform: scale(1.1); transition: all.5s ease }
 <img height="200px" width="200px" id="image"/>

I need to keep the size of 200x200, something like a zoom.我需要保持 200x200 的大小,比如缩放。 It should be solved only with the img element, not adding a parent.它应该只使用 img 元素来解决,而不是添加父元素。

Thanks!谢谢!

It's possible while using background-image without adding a parent element.在不添加父元素的情况下使用background-image是可能的。 That you can add a transition to its background-size :你可以添加一个过渡到它的background-size

 #image{ transition: background-size.5s; background-size: 100%; background-image: url(https://picsum.photos/200/200); background-position: center; } #image:hover { background-size: 120%; }
 <img height="200px" width="200px" id="image" />

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

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