aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/glossary/grid_areas/index.html
blob: bbed0c4c8cb9c46a814a05c46692fcca4643422a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: Grid Areas
slug: Glossary/Grid_Areas
tags:
  - CSS Grids
translation_of: Glossary/Grid_Areas
---
<p><strong>网格区域</strong>是网格中由一个或者多个{{glossary("grid cell", "网格单元格")}}组成的一个矩形区域。当你使用<a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Line-based_Placement_with_CSS_Grid">基于网格线位置</a>放置一个项目或者使用<a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Grid_Template_Areas">命名的网格区域</a>定义区域时,网格区域被创建。</p>

<p><img alt="Image showing a highlighted grid area" src="https://mdn.mozillademos.org/files/14771/1_Grid_Area.png" style="height: 253px; width: 380px;"></p>

<p>本质上,网格区域一定是矩形的。例如,不可能创建T形或L形的网格区域。</p>

<p>在下面的例子中,有一个网格容器包含两个网格项目,我用 {{cssxref("grid-area")}} 属性命名它们,然后用 {{cssxref("grid-template-areas")}} 把它们放在网格上。这将创建两个网格区域,一个覆盖四个网格单元格,另外一个覆盖两个。</p>

<div id="example_1">
<div class="hidden">
<pre class="brush: css">* {box-sizing: border-box;}

.wrapper {
    border: 2px solid #f76707;
    border-radius: 5px;
    background-color: #fff4e6;
}

.wrapper &gt; div {
    border: 2px solid #ffa94d;
    border-radius: 5px;
    background-color: #ffd8a8;
    padding: 1em;
    color: #d9480f;
}
</pre>
</div>

<pre class="brush: css">.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;
}
</pre>

<pre class="brush: html">&lt;div class="wrapper"&gt;
   &lt;div class="item1"&gt;Item&lt;/div&gt;
   &lt;div class="item2"&gt;Item&lt;/div&gt;
&lt;/div&gt;
</pre>

<p>{{ EmbedLiveSample('example_1', '300', '280') }}</p>
</div>

<h2 id="了解更多">了解更多</h2>

<h3 id="属性参考">属性参考</h3>

<ul>
 <li>{{cssxref("grid-template-columns")}}</li>
 <li>{{cssxref("grid-template-rows")}}</li>
 <li>{{cssxref("grid-auto-rows")}}</li>
 <li>{{cssxref("grid-auto-columns")}}</li>
 <li>{{cssxref("grid-template-areas")}}</li>
 <li>{{cssxref("grid-area")}}</li>
</ul>

<h3 id="扩展阅读">扩展阅读</h3>

<ul>
 <li>CSS Grid Layout Guide: <em><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout">Basic concepts of grid layout</a></em></li>
 <li>CSS Grid Layout Guide: <em><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Grid_Template_Areas">Grid template areas</a></em></li>
 <li><a href="https://drafts.csswg.org/css-grid/#grid-area-concept">Definition of Grid Areas in the CSS Grid Layout specification</a></li>
</ul>