aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/transform-function/rotate()/index.html
blob: e7e5807e55a2d718d90a9938ac81917427a29aba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
title: rotate()
slug: Web/CSS/transform-function/rotate()
tags:
  - CSS
  - CSS函数
  - CSS变换
translation_of: Web/CSS/transform-function/rotate()
---
<div>{{CSSRef}}</div>

<div>CSS的<strong><code>rotate()</code></strong>函数定义了一种将元素围绕一个定点(由{{ Cssxref("transform-origin") }}属性指定)旋转而不变形的转换。指定的角度定义了旋转的量度。若角度为正,则顺时针方向旋转,否则逆时针方向旋转。旋转180°也被称为点反射。</div>



<p>元素旋转的固定点 - 如上所述 - 也称为<strong>变换原点</strong>。这默认为元素的中心,但你可以使用{{ cssxref("transform-origin") }}属性设置自己的自定义变换原点。</p>

<h2 id="语法">语法</h2>

<p>{{cssxref("&lt;angle&gt;")}} 指定了 <code>rotate()</code> 的旋转程度。参数为正时,顺时针旋转;参数为负时,逆时针旋转。180° 旋转称为<em>点反演</em></p>

<pre class="syntaxbox notranslate">rotate(<em>a</em>)
</pre>

<h3 id="值"></h3>

<dl>
 <dt><em>a</em></dt>
 <dd>是一种{{ cssxref("&lt;angle&gt;") }},表示旋转的角度。 正角度表示了顺时针的旋转,负角度表示逆时针的旋转。</dd>
</dl>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">
    <p>笛卡尔坐标系 on ℝ<sup>2</sup></p>
   </th>
   <th scope="col">齐次坐标系 on ℝℙ<sup>2</sup></th>
   <th scope="col">笛卡尔坐标系 on ℝ<sup>3</sup></th>
   <th scope="col">齐次坐标系 on ℝℙ<sup>3</sup></th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td colspan="1" rowspan="2"><math> <mfenced> <mtable> <mtr><mtd>cos(a)</mtd><mtd>-sin(a)</mtd></mtr> <mtr><mtd>sin(a)</mtd><mtd>cos(a)</mtd></mtr></mtable></mfenced></math></td>
   <td><math> <mfenced><mtable><mtr><mtd>cos(a)</mtd><mtd>-sin(a)</mtd><mtd>0</mtd></mtr><mtr><mtd>sin(a)</mtd><mtd>cos(a)</mtd><mtd>0</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable> </mfenced> </math></td>
   <td colspan="1" rowspan="2"><math> <mfenced><mtable><mtr><mtd>cos(a)</mtd><mtd>-sin(a)</mtd><mtd>0</mtd></mtr><mtr><mtd>sin(a)</mtd><mtd>cos(a)</mtd><mtd>0</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable> </mfenced> </math></td>
   <td colspan="1" rowspan="2"><math> <mfenced><mtable><mtr><mtd>cos(a)</mtd><mtd>-sin(a)</mtd><mtd>0</mtd><mtd>0</mtd></mtr><mtr><mtd>sin(a)</mtd><mtd>cos(a)</mtd><mtd>0</mtd><mtd>0</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd><mtd>0</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable> </mfenced> </math></td>
  </tr>
  <tr>
   <td><code>[cos(a) sin(a) -sin(a) cos(a) 0 0]</code></td>
  </tr>
 </tbody>
</table>

<h2 id="示例">示例</h2>

<h3 id="HTML">HTML</h3>

<pre class="brush: html notranslate">&lt;div&gt;Normal&lt;/div&gt;
&lt;div class="rotated"&gt;Rotated&lt;/div&gt;</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css notranslate">div {
  width: 80px;
  height: 80px;
  background-color: skyblue;
}

.rotated {
  transform: rotate(45deg); /* Equal to rotateZ(45deg) */
  background-color: pink;
}</pre>

<h3 id="结果">结果</h3>

<p>{{EmbedLiveSample("示例","100%","200")}}</p>

<h2 id="浏览器兼容">浏览器兼容</h2>

<p>有关兼容性信息,请参阅<code><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function#Browser_compatibility">&lt;transform-function&gt;</a></code>数据类型。</p>

<h2 id="参见">参见</h2>

<ul>
 <li>{{cssxref("transform")}}</li>
 <li>{{cssxref("&lt;transform-function&gt;")}}</li>
 <li><code><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate3d">rotate3d()</a></code></li>
</ul>