The best way is to use a matrix, which allows you to combine transitions and transformations. Matrix takes 6 arguments
transform: matrix (a, b, c, d, e, f);
Where
a = x-axis scale
b = skewX
c = skewY
d = y-axis scale
e = position X
f = position Y
In this case, I set the scale on the X axis (which will change the width) to double the initial width after hovering. (value 2 means the initial time of scale 2) The scale on the Y axis does not change (value 1 means the initial value of scale 1, so the height will not change) The remaining arguments are 0, because in this case they do not need to be used.
.example { width: 30%; height: 30%; background-color: pink; position: absolute; top: 35%; left: 35%; transition: width, height, transform 1s; } .example:hover { transform: matrix(2, 0, 0, 1, 0, 0); }
<div class="example"></div>
source share