Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform: scale an image from top to bottom

Is it possible to scale a image from top to bottom, using transform on css? I have this instance here: http://jsfiddle.net/865vgz82/13/

Currently, the image in the class thumbsskin scales from the center, and expands to top, bottom and sides. It'd like to have it fixed on the top, and only scale down and to the sides. Is that possible with only css?

.thumbsskin img {
  height: 135px;
  width: 320px;
  top: 0;
  -webkit-transition: all 0.6s ease-in-out;
  transition: all 0.6s ease-in-out;
}

.thumbsskin:hover img {
  opacity: 0;
  -webkit-transform: scale(1.9);
  transform: scale(1.9);
  transform-origin: top;
}
like image 936
Gabrielle Avatar asked Sep 22 '14 01:09

Gabrielle


People also ask

What does transform scale do?

The scale() CSS function defines a transformation that resizes an element on the 2D plane. Because the amount of scaling is defined by a vector, it can resize the horizontal and vertical dimensions at different scales. Its result is a <transform-function> data type.

What is Transformorigin?

Definition and Usage The transform-origin property allows you to change the position of transformed elements. 2D transformations can change the x- and y-axis of an element. 3D transformations can also change the z-axis of an element. To better understand the transform-origin property, view a demo.

How do you skew an image in CSS?

CSS Demo: skew() This transformation is a shear mapping (transvection) that distorts each point within an element by a certain angle in the horizontal and vertical directions. The effect is as if you grabbed each corner of the element and pulled them along a certain angle.


1 Answers

By default, an element transforms with it's center point as the origin. So in this case it will scale from the center on out. You can change this by setting transform-origin, like you did.

Simple example:

div {
    margin: 3em auto;
    width: 50px;
    height: 50px;
    background: red;
}

div:hover {
    transform: scale(1.9);
}

.d2 {
    transform-origin:  top;
}
<div></div>
<hr />
<div class="d2"></div>
like image 101
Stephan Muller Avatar answered Oct 04 '22 03:10

Stephan Muller