Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate 45-degree element around vertical axis

I've got a series of elements, as shown in the image below:

enter image description here

They are rotated 45 degrees to one side (the content inside -45 degrees, to remain upright).

Now I'd like to rotate each element around a vertical axis, going through the element's center. RotateY doesn't work, as it is at a 45-degree angle.

How would you go about doing this?

like image 313
Philex Avatar asked Mar 16 '17 12:03

Philex


People also ask

What is the rule for rotating 45 degrees?

If we represent the point (x,y) by the complex number x+iy, then we can rotate it 45 degrees clockwise simply by multiplying by the complex number (1−i)/√2 and then reading off their x and y coordinates.

How do I rotate a div vertically in CSS?

rotateY() The rotateY() CSS function defines a transformation that rotates an element around the ordinate (vertical axis) without deforming it.

How do you rotate an element?

Let's take a look at the syntax for the rotate() function: transform: rotate(angle); The value “angle” represents the number of degrees the element should rotate. You can specify a rotate that is clockwise using a positive degree number (i.e. 45).


2 Answers

The trick is to set this rotation before the 45 degrees rotation:

Notice also that to make the rotation behave really as expect, you need to set it to 0 in the base state

.container {
    width: 200px;
    height: 200px;
    margin: 100px;
    border: solid 1px;
    transform: rotateY(0deg) rotate(45deg); /* needs Y at 0 deg to behave properly*/
    transition: transform 2s;
}


.container:hover {
    transform:  rotateY(180deg) rotate(45deg); /* notice the order */
}
.inner {
    margin: 50px;
    transform: rotate(-45deg);
}
<div class="container">
<div class="inner">INNER</div>
</div>
like image 145
vals Avatar answered Sep 30 '22 01:09

vals


This is how I interpret the question. I'm not very happy with the demo since it needs a lot of structure. But maybe you can verify the behavior?

Basically I use a wrapper to rotate on the y-axis. It is key to set the transform origin to the center. The additional wrapper is used to prevent a flickering on mouse hover.

https://jsfiddle.net/nm59mqky/1/

.tile {
  transform: rotateY(0);
  transform-origin: center center;  
}

.wrapper:hover .tile {
  transform: rotateY(180deg);
}
like image 25
Philipp Lehmann Avatar answered Sep 30 '22 00:09

Philipp Lehmann