放大div内的图像而无需移动div

2 html css css3 css-transitions css-transforms

如何在悬停时没有实际的div缩放的情况下在此div缩放内制作图像?因此,我只希望图像放大。

这是代码:

<div id="container">
    <img id="image" src="some-image">
</div>
Run Code Online (Sandbox Code Playgroud)

LGS*_*Son 7

使用 transform: scale

#container {
  display: inline-block;
  margin: 20px;
  border: 1px solid black;
  overflow: hidden;            /* clip the excess when child gets bigger than parent */
}
#container img {
  display: block;
  transition: transform .4s;   /* smoother zoom */
}
#container:hover img {
  transform: scale(1.3);
  transform-origin: 50% 50%;
}
Run Code Online (Sandbox Code Playgroud)
<div id="container">
    <img id="image" src="http://placehold.it/150">
</div>
Run Code Online (Sandbox Code Playgroud)