order CSS property sets the order to lay out an item in a flex or grid container. Items in a container are sorted by ascending order value and then by their source code order.

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.

句法

/* <integer> values */
order: 5;
order: -5;
/* Global values */
order: inherit;
order: initial;
order: unset;
					

Since order is only meant to affect the visual order of elements and not their logical or tab order. order must not be used on non-visual media such as speech .

<integer>

Represents the ordinal group to be used by the item.

可访问性关注

使用 order property will create a disconnect between the visual presentation of content and DOM order. This will adversely affect users experiencing low vision navigating with the aid of assistive technology such as a screen reader. If the visual (css) order is important, then screen reader users will not have access to the correct reading order.

形式定义

初始值 0
适用于 flex items and absolutely-positioned flex container children
继承 no
计算值 如指定
动画类型 an integer

形式句法

<integer>
					

范例

Ordering items in a flex container

This example uses CSS to create a classic two-sidebar layout surrounding a content block. The Flexible Box Layout Module automatically creates blocks of equal vertical size and uses as much horizontal space as available.

HTML

<header>...</header>
<main>
  <article>Article</article>
  <nav>Nav</nav>
  <aside>Aside</aside>
</main>
<footer>...</footer>
					

CSS

main { display: flex;  text-align:center; }
main > article { flex:1;        order: 2; }
main > nav     { width: 200px;  order: 1; }
main > aside   { width: 200px;  order: 3; }
					

结果

规范

规范 状态 注释
CSS Flexible Box Layout Module
The definition of 'order' in that specification.
候选推荐 初始定义
初始值 0
适用于 flex items and absolutely-positioned flex container children
继承 no
计算值 如指定
动画类型 an integer

浏览器兼容性

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
order Chrome 完整支持 29 Edge 完整支持 12 Firefox 完整支持 20 注意事项
完整支持 20 注意事项
注意事项 Since Firefox 28, multi-line flexbox is supported.
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
完整支持
Prefixed Implemented with the vendor prefix: -webkit-
Disabled layout.css.prefixes.webkit preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
不支持 18 — 28 Disabled
Disabled ). To change preferences in Firefox, visit
IE 完整支持 11
完整支持 11
完整支持 10 Prefixed
Prefixed Implemented with the vendor prefix: -ms-
Opera 完整支持 12.1 Safari 完整支持 9 WebView Android 完整支持 4.4 Chrome Android 完整支持 29 Firefox Android 完整支持 20 注意事项
完整支持 20 注意事项
注意事项 Since Firefox 28, multi-line flexbox is supported.
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
完整支持
Prefixed Implemented with the vendor prefix: -webkit-
Disabled layout.css.prefixes.webkit preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
不支持 18 — 28 Disabled
Disabled ). To change preferences in Firefox, visit
Opera Android 完整支持 12.1 Safari iOS 完整支持 9 Samsung Internet Android 完整支持 2.0

图例

完整支持

完整支持

见实现注意事项。

见实现注意事项。

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

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

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

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

另请参阅

元数据

  • 最后修改: