--- title: rotate slug: Web/CSS/rotate translation_of: Web/CSS/rotate ---
rotate
属性允许你单独设置transform
的旋转属性。这种映射方式可以让我们更方便的设置我们想要的效果,并且避免了简写形式需要记忆属性顺序的不方便之处。
/* Keyword values */ scale: none; /* Angle value */ rotate: 90deg; rotate: 0.25turn; rotate: 1.57rad; /* x, y, or z axis name plus angle */ rotate: x 90deg; rotate: y 0.25turn; rotate: z 1.57rad; /* Vector plus angle value */ rotate: 1 1 1 90deg;
rotate()
(2D rotation) function."x"
, "y
", or "z"
), plus an {{cssxref("<angle>")}} specifying the angle to rotate the element through. Equivalent to a rotateX()
/rotateY()
/rotateZ()
(3D rotation) function.rotate3d()
(3D rotation) function.none
{{csssyntax}}
<div> <p class="rotate">Rotation</p> </div>
* { box-sizing: border-box; } html { font-family: sans-serif; } div { width: 150px; margin: 0 auto; } p { padding: 10px 5px; border: 3px solid black; border-radius: 20px; width: 150px; font-size: 1.2rem; text-align: center; } .rotate { transition: rotate 1s; } div:hover .rotate { rotate: 1 -0.5 1 180deg; }
{{EmbedLiveSample('Examples')}}
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS Transforms 2', '#individual-transforms', 'individual transforms')}} | {{Spec2('CSS Transforms 2')}} | Initial definition. |
{{cssinfo}}
{{Compat("css.properties.rotate")}}