翻譯不完整。 請幫助我們翻譯這篇文章!
transform CSS 屬性可以讓你修改 CSS 可視化格式模型(visual formatting model)的空間維度。使用此屬性,元素可以被平移、旋轉、縮放和傾斜。
如果這個屬性的值不是 none,將會建立一個 stacking context。在這個情況下,此元素將被其所包含的 position: fixed 元素當成一個 containing block。
語法
transform 屬性可能被指定為關鍵字值 none 或著一或多個 <transform-function> 值。
值
<transform-function>- 可使用一個或多個 CSS transform functions。複合的transforms 會由左至右的順序來套用。
none- 設定為沒有套用任何 transform。
標準語法
none | <transform-list>where
<transform-list> = <transform-function>+where
<transform-function> = <matrix()> | <translate()> | <translateX()> | <translateY()> | <scale()> | <scaleX()> | <scaleY()> | <rotate()> | <skew()> | <skewX()> | <skewY()> | <matrix3d()> | <translate3d()> | <translateZ()> | <scale3d()> | <scaleZ()> | <rotate3d()> | <rotateX()> | <rotateY()> | <rotateZ()> | <perspective()>where
<matrix()> = matrix( <number>#{6} )
<translate()> = translate( <length-percentage> , <length-percentage>? )
<translateX()> = translateX( <length-percentage> )
<translateY()> = translateY( <length-percentage> )
<scale()> = scale( <number> , <number>? )
<scaleX()> = scaleX( <number> )
<scaleY()> = scaleY( <number> )
<rotate()> = rotate( [ <angle> | <zero> ] )
<skew()> = skew( [ <angle> | <zero> ] , [ <angle> | <zero> ]? )
<skewX()> = skewX( [ <angle> | <zero> ] )
<skewY()> = skewY( [ <angle> | <zero> ] )
<matrix3d()> = matrix3d( <number>#{16} )
<translate3d()> = translate3d( <length-percentage> , <length-percentage> , <length> )
<translateZ()> = translateZ( <length> )
<scale3d()> = scale3d( <number> , <number> , <number> )
<scaleZ()> = scaleZ( <number> )
<rotate3d()> = rotate3d( <number> , <number> , <number> , [ <angle> | <zero> ] )
<rotateX()> = rotateX( [ <angle> | <zero> ] )
<rotateY()> = rotateY( [ <angle> | <zero> ] )
<rotateZ()> = rotateZ( [ <angle> | <zero> ] )
<perspective()> = perspective( <length> )where
<length-percentage> = <length> | <percentage>
範例
HTML
<p>Transformed element</p>
CSS
p {
border: solid red;
transform: translate(100px) rotate(20deg);
transform-origin: 0 -250px;
}
結果
請參考使用 CSS transforms 以及 <transform-function> 的更多範例。
規範
| Specification | Status | Comment |
|---|---|---|
| CSS Transforms Level 2 The definition of 'transform' in that specification. |
Editor's Draft | Adds 3D transform functions. |
| CSS Transforms Level 1 The definition of 'transform' in that specification. |
Working Draft | Initial definition. |
| 預設值 | none |
|---|---|
| Applies to | transformable elements |
| 繼承與否 | no |
| Percentages | refer to the size of bounding box |
| Media | visual |
| Computed value | as specified, but with relative lengths converted into absolute lengths |
| Animation type | a transform |
| Canonical order | the unique non-ambiguous order defined by the formal grammar |
| Creates stacking context | yes |
瀏覽器相容性
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
transform | Chrome
Full support
36
| Edge
Full support
12
| Firefox
Full support
16
| IE
Full support
10
| Opera
Full support
23
| Safari
Full support
9
| WebView Android
Full support
37
| Chrome Android
Full support
36
| Firefox Android
Full support
16
| Opera Android
Full support
24
| Safari iOS
Full support
9
| Samsung Internet Android
Full support
3.0
|
| 3D support | Chrome Full support 12 | Edge Full support 12 | Firefox Full support 16 | IE
Full support
10
| Opera Full support 15 | Safari Full support 4 | WebView Android
Full support
3
| Chrome Android Full support 18 | Firefox Android Full support 16 | Opera Android Full support 14 | Safari iOS Full support 3.2 | Samsung Internet Android Full support 1.0 |
Legend
- Full support
- Full support
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.
- Requires a vendor prefix or different name for use.
- Requires a vendor prefix or different name for use.
參見
- 使用 CSS transforms
<transform-function>data type- A cross-browser 2D transform plugin for jQuery