Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zoom in on hover image and keep same size

I am trying to have the hover zoom feature for my website, however, I have seen other examples and my code seems to be the same, however the dimensions of the image doesn't stay the same. Any ideas what could be the problem?

.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

like image 760
Dee Avatar asked Mar 03 '16 21:03

Dee


People also ask

How do you hover over a picture and make it bigger CSS?

First, use the <img> tag of HTML to add an image to the code. Then make use of the :hover pseudo-class and change the CSS accordingly to enlarge the image. We must also use the transition and transform CSS properties to achieve our goal.

How do you scale up on hover?

Try moving your mouse over this box: It scales up exactly 1.5 times the original size — so it becomes 50% bigger when you move your mouse over (hover) it. The CSS transform property's scale method can either increase or decrease the size of elements.

How do you use hover zoom?

Zoom images/videos on all your favorite websites (Facebook, Amazon, etc). Simply hover your mouse over the image to enlarge it. Hover your mouse over any image on the supported websites and the extension will automatically enlarge the image to its full size, making sure that it still fits into the browser window.

How do I get rid of the zoom hover effect?

To remove it, Create a child theme . Open functions. php file of the child theme and add following code: function remove_image_zoom_support() { remove_theme_support( 'wc-product-gallery-zoom' ); } add_action( 'wp', 'remove_image_zoom_support', 100 );


1 Answers

It appears that you are trying to scale the image which is fine but to restrict what is actually seen requires that the image be scaled within a container.

Then when the image is scaled, the container will hide anything that would normally "spill out" if you didn't hide the overlflow.

So, like this:

.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>
like image 163
Paulie_D Avatar answered Oct 17 '22 16:10

Paulie_D