Image hover coming out of the box


.snippet-box:hover img {-webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;}

I am using the above CSS on some image hover, but it is coming out of the DIV. Is there a way we can make sure that it doesnt comes out of the div?


Without seeing the markup and the rest of the styles I doubt anyone can give you much of an answer.


Ok I am replicating this in the codepen.



May be this Video GIF can help you to see this →

I do not want that this should come out of the div, but enlarge within.


@codeispoetry: that still doesn't show us the HTML and other CSS rules you have in place. If you give us the fuill code, we can see the issue for ourselves. Showing us a picture tells us little or nothing about the code.


As a rough guess without seeing the full code, I think overflow: hidden on the container may help.


I think @codeispoetry is using transform:scale(); along with the transitions in the css from post 1.

In the screenshot you notice the enlarged image is not pushing on the other boxes around it.

The Transform Rendering Model explains that behavior.

For elements whose layout is governed by the CSS box model, the transform property does not affect the flow of the content surrounding the transformed element. However, the extent of the overflow area takes into account transformed elements. This behavior is similar to what happens when elements are offset via relative positioning. Therefore, if the value of the overflow property is scroll or auto, scrollbars will appear as needed to see content that is transformed outside the visible area.

So yes, overflow:hidden; could be used to keep a scaled image within it's parent box.

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Image Transform Zoom</title>

.zoom {
   margin:2em auto;
.zoom img {
   margin:0 0 1em;
   transition:transform 0.5s;
.zoom img:hover {
   transform:scale(1.7) ;


 <figure class="zoom">
    <img src="" width="300" height="200" alt="">
    <figcaption>Mouseover image to enlarge</figcaption>



This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.