grid-template-areas
CSS властивість, що визначає іменовані grid areas.
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.
Ці області не відносяться до певного грід-елемента, але можуть посилатися з властивостей грід-розташуванняgrid-row-start
, grid-row-end
, grid-column-start
, grid-column-end
, та їх скорочень grid-row
, grid-column
, і grid-area
.
Syntax
/* 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;
Values
none
- Грід-контейнер не визначає жодні іменовані грід-області.
<string>
+- Ряд створюється для кожного окремого рядка, а колонка для кожної клітинки рядка. Декілька іменованих клітинок у рядках та поміж ними створюють одну іменовану грід-область, що об'єднує відповідні клітинки. Оголошення непридатне, якщо ці клітинки утворюють прямокутник.
Formal syntax
Example
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;
}
Result
Specifications
Specification | Status | Comment |
---|---|---|
CSS Grid Layout The definition of 'grid-template-areas' in that specification. |
Candidate Recommendation | Initial definition |
Initial value | none |
---|---|
Applies to | grid containers |
Inherited | no |
Computed value | as specified |
Animation type | discrete |
Browser compatibility
BCD tables only load in the browser
See also
- Related CSS properties:
grid-template-rows
,grid-template-columns
,grid-template
- Grid Layout Guide: Grid template areas
- Video tutorial: Grid Template Areas