Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Prevent Overflow when Using transform SCALE

Tags:

html

css

i have a problem when using transform: scale();

basically, i'm using this scale on Image that has overflow:hidden

check this fiddle out for live action : https://jsfiddle.net/ns3vm3x6/

HTML

<div id="container1">
  <img src="http://lorempixel.com/400/200">
</div>
<p> i want this image to scale just like #example no. 2. how to achive this one? </p>
<br><br>
<div id="container2">
  <img src="http://lorempixel.com/400/200">
</div>

CSS

#container1 {width:100%; height:200px; border:2px solid red;
 overflow-x:scroll; overflow-y:hidden; white-space:no-wrap; }

#container2 {width:100%; height:200px; border:2px solid red; white- space:no-wrap;  }
img {width:200px; height:200px; transition:transform 1s linear; }
img:hover {transform:scale(2); }

How to prevent that overflow when scaling image?

what's wrong with my code?

thanks in advance...

like image 695
Ching Ching Avatar asked Apr 02 '16 07:04

Ching Ching


1 Answers

You need to set position: absolute for img

img {width:200px; 
height:200px; 
transition:transform 1s linear;
position: absolute; 
}

JSFiddle

like image 84
Pedram Avatar answered Oct 16 '22 11:10

Pedram