Grid Areas - MDN Web Docs Glossary: Definitions of Web-related terms 编辑
A grid area is one or more grid cells that make up a rectangular area on the grid. Grid areas are created when you place an item using line-based placement or when defining areas using named grid areas.
Grid areas must be rectangular in nature; it is not possible to create, for example, a T- or L-shaped grid area.
In the example below I have a grid container with two grid items. I have named these with the grid-area
property and then laid them out on the grid using grid-template-areas
. This creates two grid areas, one covering four grid cells, the other two.
* {box-sizing: border-box;}
.wrapper {
border: 2px solid #f76707;
border-radius: 5px;
background-color: #fff4e6;
}
.wrapper > div {
border: 2px solid #ffa94d;
border-radius: 5px;
background-color: #ffd8a8;
padding: 1em;
color: #d9480f;
}
.wrapper {
display: grid;
grid-template-columns: repeat(3,1fr);
grid-template-rows: 100px 100px;
grid-template-areas:
"a a b"
"a a b";
}
.item1 {
grid-area: a;
}
.item2 {
grid-area: b;
}
<div class="wrapper">
<div class="item1">Item</div>
<div class="item2">Item</div>
</div>
Learn More
Property reference
Further reading
- CSS Grid Layout Guide: Basic concepts of grid layout
- CSS Grid Layout Guide: Grid template areas
- Definition of Grid Areas in the CSS Grid Layout specification
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论