放大悬停图像并保持相同大小

Zoom in on hover image and keep same size

我正在尝试为我的网站添加悬停缩放功能,但是,我看到了其他示例并且我的代码似乎相同,但图像的尺寸并没有保持不变。任何想法可能是什么问题?

.imgBox {
  display: inline-block;
  overflow: hidden !important;
  transition: .3s ease-in-out
}

  .imgBox {
    display: inline-block;
    overflow: hidden !important;
    transition: .3s ease-in-out
  }
  .imgBox:hover {
    opacity: 0.6;
    filter: alpha(opacity=30);
    transform: scale(1.3);
  }
<div class="large-3 medium-6 small-12 columns">
  <h2>Heading 1</h2>
  <img class="imgBox" src="http://techmadeplain.com/img/2014/300x200.png" />
  <p>Paragraph here</p>
</div>

JSFiddle

看来您正在尝试缩放图像,这很好,但要限制实际看到的内容需要在容器内缩放图像

然后当缩放图像时,如果您没有隐藏溢出,容器将隐藏通常 "spill out" 的任何内容。

所以,像这样:

.imgBox { /* now a container for the image */
    display: inline-block; /* shrink wrap to image */
    overflow: hidden; /* hide the excess */
  }
  .imgBox img {
    display: block; /* no whitespace */
    transition: .3s ease-in-out;
  }
  .imgBox:hover img {
    transform: scale(1.3);
  }
<div class="large-3 medium-6 small-12 columns">
  <h2>Heading 1</h2>
  <div class="imgBox">
    <img src="http://lorempixel.com/image_output/food-q-c-300-200-9.jpg" />
  </div>
  <p>Paragraph here</p>
</div>

Paulie 肯定是对的,但还有另一种方法可以使用 background-image 而不是 img 标签

  .imageWrapper{
    background-image:url("http://techmadeplain.com/img/2014/300x200.png");
    width:300px;
    height:200px;
    background-size:100%;  
    background-position: center center;
    transition: .3s ease-in-out;
  }

  .imageWrapper:hover{
    background-size:130%;
  }
<div class="large-3 medium-6 small-12 columns">
  <h2>Heading 1</h2>
  <div class='imageWrapper'> 
  </div>  
  <p>Paragraph here</p>
</div>