<flex> CSS data type denotes a flexible length within a grid container. It is used in grid-template-columns , grid-template-rows and other related properties.

句法

<flex> data type is specified as a <number> followed by the unit fr fr unit represents a fraction of the leftover space in the grid container. As with all CSS dimensions, there is no space between the unit and the number.

范例

Examples of correct values for the fr data type

1fr    /* Using an integer value */
2.5fr  /* Using a float value */
					

Example of use in a tracklisting for CSS Grid layout

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 2.5fr 1.5fr;
}
					

规范

规范 状态 注释
CSS 栅格布局
The definition of '<flex>' 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
<flex> Chrome 完整支持 29 Edge 完整支持 12 Firefox 完整支持 40 IE 完整支持 10 Opera 完整支持 28 Safari 完整支持 10.1 WebView Android 完整支持 57 Chrome Android 完整支持 29 Firefox Android 完整支持 40 Opera Android 完整支持 28 Safari iOS 完整支持 10.3 Samsung Internet Android 完整支持 2.0

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: