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

网格模板区 | grid-template-areas

grid-template-areas

grid-template-areasCSS属性指定命名网格区域。

/* Keyword value */ grid-template-areas: none; /* <string> values */ grid-template-areas: "a b"; grid-template-areas: "a b b" "a c d"; /* Global values */ grid-template-areas: inherit; grid-template-areas: initial; grid-template-areas: unset;

这些领域不与任何特定的网格项目相关联,但可以从电网布局属性来引用grid-row-startgrid-row-endgrid-column-startgrid-column-end,和他们的速记grid-rowgrid-columngrid-area

初始值none
适用于网格容器
遗传没有
媒体视觉
计算值作为指定
动画类型离散的
规范的顺序形式语法定义的独特的非模糊顺序

语法

取值

none网格容器不定义任何指定的网格区域。

形式语法

none | <string>+

HTML

<section id="page"> <header>Header</header> <nav>Navigation</nav> <main>Main area</main> <footer>Footer</footer> </section>

CSS

#page { display: grid; width: 100%; height: 250px; grid-template-areas: "head head" "nav main" "nav foot"; grid-template-rows: 50px 1fr 30px; grid-template-columns: 150px 1fr; } #page > header { grid-area: head; background-color: #8ca0ff; } #page > nav { grid-area: nav; background-color: #ffa08c; } #page > main { grid-area: main; background-color: #ffff64; } #page > footer { grid-area: foot; background-color: #8cffa0; }

结果

规范

SpecificationStatusComment
CSS Grid LayoutThe definition of 'grid-template-areas' in that specification.Candidate RecommendationInitial definition

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support57.01No support352.0 (52.0)2No support344410.1

FeatureAndroid WebviewChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support57.0157.0152.0 (52.0)2No support34410.3