在线文档教程
CSS
网格布局 | Grid Layout

网格自动列 | grid-auto-columns

grid-auto-columns

grid-auto-columnsCSS属性指定的隐含创建的网格列的大小轨道。

/* Keyword values */ grid-auto-columns: min-content; grid-auto-columns: max-content; grid-auto-columns: auto; /* <length> values */ grid-auto-columns: 100px; grid-auto-columns: 20cm; grid-auto-columns: 50vmax; /* <percentage> values */ grid-auto-columns: 10%; grid-auto-columns: 33.3%; /* <flex> values */ grid-auto-columns: 0.5fr; grid-auto-columns: 3fr; /* minmax() values */ grid-auto-columns: minmax(100px, auto grid-auto-columns: minmax(max-content, 2fr grid-auto-columns: minmax(20%, 80vmax /* fit-content() values */ grid-auto-columns: fit-content(400px grid-auto-columns: fit-content(5cm grid-auto-columns: fit-content(20% /* multiple track-size values */ grid-auto-columns: min-content max-content auto; grid-auto-columns: 100px 150px 390px; grid-auto-columns: 10% 33.3%; grid-auto-columns: 0.5fr 3fr 1fr; grid-auto-columns: minmax(100px, auto) minmax(max-content, 2fr) minmax(20%, 80vmax grid-auto-columns: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px /* Global values */ grid-auto-columns: inherit; grid-auto-columns: initial; grid-auto-columns: unset;

如果一个网格项目被定位到一个没有明确的大小的列中,则grid-template-columns隐式网格轨道被创建来保存它。这可以通过显式定位到超出范围的列中,或通过自动布局算法创建附加列来实现。

初始值auto
应用于grid containers
是否继承no
百分比refer to corresponding dimension of the content area
适用媒体visual
计算值the percentage as specified or the absolute length
动画类型discrete
规范顺序the unique non-ambiguous order defined by the formal grammar

语法

取值

<length>是一个非负的长度。相对于网格容器的块大小<percentage>是一个非负值<percentage>。如果网格容器的块大小是不确定的,百分比值将被视为像auto。

当出现在minmax()符号之外时,它意味着自动最小(即minmax(auto, <flex>))。

max-content是表示占据网格轨道的网格项目的最大最大内容贡献的关键字。

注意:auto轨道大小(只有auto轨道大小)可以通过align-contentjustify-content属性进行拉伸。

形式语法

<track-size>+where <track-size> = <track-breadth> | minmax( <inflexible-breadth> , <track-breadth> ) | fit-content( [ <length> | <percentage> ] ) where <track-breadth> = <length-percentage> | <flex> | min-content | max-content | auto <inflexible-breadth> = <length> | <percentage> | min-content | max-content | auto where <length-percentage> = <length> | <percentage>

HTML内容

<div id="grid">   <div id="item1"></div>   <div id="item2"></div>   <div id="item3"></div> </div>

CSS内容

#grid { height: 100px; display: grid; grid-template-areas: "a a"; grid-gap: 10px; grid-auto-columns: 200px; } #grid > div { background-color: lime; }

规格

SpecificationStatusComment
CSS Grid LayoutThe definition of 'grid-auto-columns' in that specification.Candidate RecommendationInitial definition

浏览器兼容性

FeatureChromeFirefox (Gecko)Internet ExplorerEdgeOperaSafari
Basic support57.0152.0 (52.0)210.0-ms320-ms344410.1

FeatureAndroid WebviewChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support57.0157.0152.0 (52.0)210.0-ms344No support