transition CSS 特性为 shorthand property for transition-property , transition-duration , transition-timing-function ,和 transition-delay .

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

Transitions enable you to define the transition between two states of an element. Different states may be defined using pseudo-classes like :hover or :active or dynamically set using JavaScript.

组成特性

此特性是下列 CSS 特性的简写:

句法

/* Apply to 1 property */
/* property name | duration */
transition: margin-right 4s;
/* property name | duration | delay */
transition: margin-right 4s 1s;
/* property name | duration | timing function */
transition: margin-right 4s ease-in-out;
/* property name | duration | timing function | delay */
transition: margin-right 4s ease-in-out 1s;
/* Apply to 2 properties */
transition: margin-right 4s, color 1s;
/* Apply to all changed properties */
transition: all 0.5s ease-out;
/* Global values */
transition: inherit;
transition: initial;
transition: unset;
					

transition property is specified as one or more single-property transitions, separated by commas.

Each single-property transition describes the transition that should be applied to a single property (or the special values all and none ). It includes:

how things are handled when lists of property values aren't the same length. In short, extra transition descriptions beyond the number of properties actually being animated are ignored.

形式定义

初始值 as each of the properties of the shorthand:
适用于 所有元素, ::before and ::after pseudo-elements
继承 no
计算值 as each of the properties of the shorthand:
动画类型 discrete

形式句法

<single-transition>#

where
<single-transition> = [ none | <single-transition-property> ] || <time> || <timing-function> || <time>

where
<single-transition-property> = all | <custom-ident>
<timing-function> = linear | <cubic-bezier-timing-function> | <step-timing-function>

where
<cubic-bezier-timing-function> = ease | ease-in | ease-out | ease-in-out | cubic-bezier(<number <a href="/en-US/docs/CSS/Value_definition_syntax#Brackets" title="Brackets: enclose several entities, combinators, and multipliers to transform them as a single component">[0,1]>, <number>, <number <a href="/en-US/docs/CSS/Value_definition_syntax#Brackets" title="Brackets: enclose several entities, combinators, and multipliers to transform them as a single component">[0,1]>, <number>)
<step-timing-function> = step-start | step-end | steps(<integer>[, <step-position>]?)

where
<step-position> = jump-start | jump-end | jump-none | jump-both | start | end

范例

Simple example

This example performs a four-second font size transition with a one-second delay when the user hovers over the element.

HTML

<a class="target">Hover over me</a>
					

CSS

.target {
  font-size: 14px;
  transition: font-size 4s 1s;
}
.target:hover {
  font-size: 36px;
}
					

There are several more examples of CSS transitions included in the Using CSS transitions article.

规范

规范 状态 注释
CSS Transitions
The definition of 'transition' in that specification.
工作草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
transition Chrome 完整支持 26 Edge 完整支持 12 Firefox 完整支持 16 注意事项
完整支持 16 注意事项
注意事项 Before Firefox 57, transitions do not work when transitioning from a text-shadow with a color specified to a text-shadow without a color specified (see bug 726550 ).
注意事项 Before Firefox 57, cancelling a filling animation (for example, with animation-fill-mode: forwards set) can trigger a transition set on the same element, although only once (see bug 1192592 and these test cases for more information).
注意事项 Before Firefox 57, the background-position property can't be transitioned between two values containing different numbers of <position> values, for example background-position: 10px 10px; and background-position: 20px 20px, 30px 30px; (见 bug 1390446 ).
完整支持 4 Prefixed
Prefixed Implemented with the vendor prefix: -moz-
preference (needs to be set to ). To change preferences in Firefox, visit about:config.
IE 完整支持 10
完整支持 10
完整支持 10 Prefixed
Prefixed Implemented with the vendor prefix: -ms-
Opera 完整支持 12.1
完整支持 12.1
Prefixed Implemented with the vendor prefix: -webkit-
不支持 10.1 — 15 Prefixed
Prefixed Implemented with the vendor prefix: -o-
Safari 完整支持 9 WebView Android 完整支持 ≤37 Chrome Android 完整支持 26 Firefox Android 完整支持 16 注意事项
完整支持 16 注意事项
注意事项 Before Firefox 57, transitions do not work when transitioning from a text-shadow with a color specified to a text-shadow without a color specified (see bug 726550 ).
注意事项 Before Firefox 57, cancelling a filling animation (for example, with animation-fill-mode: forwards set) can trigger a transition set on the same element, although only once (see bug 1192592 and these test cases for more information).
注意事项 Before Firefox 57, the background-position property can't be transitioned between two values containing different numbers of <position> values, for example background-position: 10px 10px; and background-position: 20px 20px, 30px 30px; (见 bug 1390446 ).
完整支持 4 Prefixed
Prefixed Implemented with the vendor prefix: -moz-
preference (needs to be set to ). To change preferences in Firefox, visit about:config.
Opera Android 完整支持 12.1
完整支持 12.1
Prefixed Implemented with the vendor prefix: -webkit-
不支持 10.1 — 14 Prefixed
Prefixed Implemented with the vendor prefix: -o-
Safari iOS 完整支持 9 Samsung Internet Android 完整支持 1.5
Gradients Chrome 不支持 No Edge 不支持 12 — 79 Firefox 不支持 No IE 完整支持 10 Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. CSS Transitions
  4. 指南
    1. Using CSS transitions
  5. 特性
    1. transition
    2. transition-delay
    3. transition-duration
    4. transition-property
    5. transition-timing-function

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1