CSS 中的 rotateZ() 函数用于在三维平面上围绕 z 轴旋转元素而不会引起任何变形。结果是 transform() 数据类型。
旋转轴穿过变换原点。使用 CSS 属性 transform-origin,可以更改和自定义转换原点。
rotateZ() 函数创建的元素的旋转由 <angle> 指定。如果角度值为正,则旋转的运动将是顺时针旋转的,如果值为负,则旋转的运动将是逆时针旋转的。
可能的值
函数 rotateZ() 只能接受一个参数。它指定了旋转角度。
- <angle>:以度数表示。正角使元件顺时针方向旋转;而负值则逆时针旋转。
语法
transform: rotateZ(35deg) | rotateZ(-35deg);
CSS rotateZ() - 值的组合
以下是 rotateZ() 函数的示例,其中包含各种值作为参数,例如 deg、turn、grads:
<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>