CSS 函数 - rotateZ()



CSS 中的 rotateZ() 函数用于在三维平面上围绕 z 轴旋转元素,而不会导致任何变形。结果是 transform() 数据类型。

旋转轴穿过 变换原点。使用 CSS 属性 transform-origin,可以更改和自定义变换原点。

rotateZ() 函数创建的元素旋转由 <angle> 指定。如果角度值为正,则旋转方向为顺时针;如果值为负,则旋转方向为逆时针。

可能的值

rotateZ() 函数只能接受一个参数。它指定旋转角度。

  • <angle>:以度数表示。正角度使元素顺时针旋转;负值使元素逆时针旋转。

语法

transform: rotateZ(35deg) | rotateZ(-35deg);

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

CSS rotateZ() - 值组合

以下是用各种值(如 deg、turn、grads)作为参数的 rotateZ() 函数示例。

Open Compiler
<html> <head> <style> #container { display: flex; } #sample-div { height: 100px; width: 100px; border: 2px solid black; background-image: url('images/logo.png'); margin-bottom: 2em; } section { padding: 25px; border: 2px solid red; } .rotate-z-positive { transform: rotateZ(45deg); background-image: url('images/logo.png'); } .rotate-z-negative { transform: rotateZ(-75deg); background-image: url('images/logo.png'); } .rotate-z-turn { transform: rotateZ(2.5turn); background-image: url('images/logo.png'); } .rotate-z-grads { transform: rotateZ(2grads); background-image: url('images/logo.png'); } </style> </head> <body> <div id="container"> <section> <p>no rotation</p> <div id="sample-div"></div> </section> <section> <p>rotateZ(45deg)</p> <div class="rotate-z-positive" id="sample-div"></div> </section> <section> <p>rotateZ(-75deg)</p> <div class="rotate-z-negative" id="sample-div"></div> </section> <section> <p>rotateZ(2.5turn)</p> <div class="rotate-z-turn" id="sample-div"></div> </section> <section> <p>rotateZ(2grads)</p> <div class="rotate-z-grads" id="sample-div"></div> </section> </div> </body> </html>
广告