Grid Tracks - MDN Web Docs Glossary: Definitions of Web-related terms 编辑
A grid track is the space between two grid lines. They are defined in the explicit grid by using the grid-template-columns
and grid-template-rows
properties or the shorthand grid
or grid-template
properties. Tracks are also created in the implicit grid by positioning a grid item outside of the tracks created in the explicit grid.
The image below shows the first row track on a grid.
Track sizing in the explicit grid
When defining grid tracks using grid-template-columns
and grid-template-rows
you may use any length unit, and also the flex unit, fr
which indicates a portion of the available space in the grid container. The example below demonstrates a grid with three column tracks, one of 200 pixels, the second of 1fr, the third of 3fr. Once the 200 pixels has been subtracted from the space available in the grid container, the remaining space is divided by 4. One part is given to column 2, 3 parts to column 3.
* {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: 200px 1fr 3fr;
}
<div class="wrapper">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
<div>Five</div>
</div>
Track sizing in the implicit grid
Tracks created in the implicit grid are auto-sized by default, however you can define a size for these tracks using the grid-auto-rows
and grid-auto-columns
properties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论