1

I always assumed that CSS transform operations would occur in order, so I was a bit surprised seeing that transform: rotate(45deg) scaleX(2) is displaying a rotated rectangle and not a rhombus.

It works when applying the scale to the parent element. However my question is: How can I transform a

Example (how it is not working): https://jsfiddle.net/avpqjL0y/1/

enter image description here

lal12
  • 131
  • 10

3 Answers3

1

Simply swipe the order of the values in the transform property:

transform: scaleX(2) rotate(45deg)

transform gets executed from right to left. See: How to apply multiple transforms in CSS?

You can also use @keyframes to achieve this effect. See: https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes

Guy Sela
  • 78
  • 6
0

You can use scale and rotate in this order, to get your result.

#main {
  display:flex;
  justify-content:center;
  align-items: center;
  height:100vh;
}
#inner {
  width:100px;
  height:100px;
  background-color: #f00;
  transform:scaleX(.8) rotate(45deg);
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div id="main">
    <div id="inner"></div>
  </div>
</body>
</html>
Kumar Gaurav
  • 738
  • 4
  • 11
0

You must using scale instate of scaleX ;)

div {
//...
    transform: rotate(45deg) scale(2) 

    }
reza ostadi
  • 197
  • 1
  • 10