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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
---
title: place-content
slug: Web/CSS/place-content
translation_of: Web/CSS/place-content
---
<div>{{CSSRef}}</div>
<p> <code><strong>place-content</strong></code> 属性是{{CSSxRef("align-content")}} 和 {{CSSxRef("justify-content")}}的简写. 使用这两个属性的值可以用于任何的布局情况。</p>
<div>{{EmbedInteractiveExample("pages/css/place-content.html")}}</div>
<div class="hidden">这些交互式案列存储在Github. 如果愿意资助这些案列, 可以克隆 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> 以及发送请求.</div>
<h2 id="语法">语法</h2>
<pre class="brush:css no-line-numbers notranslate">/* Positional alignment */
/* align-content does not take left and right values */
place-content: center start;
place-content: start center;
place-content: end left;
place-content: flex-start center;
place-content: flex-end center;
/* Baseline alignment */
/* justify-content does not take baseline values */
place-content: baseline center;
place-content: first baseline space-evenly;
place-content: last baseline right;
/* Distributed alignment */
place-content: space-between space-evenly;
place-content: space-around space-evenly;
place-content: space-evenly stretch;
place-content: stretch space-evenly;
/* Global values */
place-content: inherit;
place-content: initial;
place-content: unset;</pre>
<p>第一个值为 {{CSSxRef("align-content")}} 属性, 第二个值为 {{CSSxRef("justify-content")}} .</p>
<div class="warning">
<p><strong>非常重要</strong>:如果没有设置第二个值, 那么第二个的值与第一个相等, 此前提是第一个值对两个属性都是有效的。如果设置的这个值对两个属性都无效,那么整个设置的值就是无效的。</p>
</div>
<h3 id="参考值">参考值</h3>
<dl>
<dt><code>start</code></dt>
<dd>所有的子元素堆叠在父元素上合适的轴线上的起点对齐。</dd>
<dt><code>end</code></dt>
<dd>所有的子元素堆叠在父元素上合适的轴线上的终点对齐</dd>
<dt><code>flex-start</code></dt>
<dd>所有的子元素堆叠在父元素的主轴或交叉轴上起点对齐,主要取决于flex-direction的设置。<br>
仅适用于flex布局的子元素.。如果父元素没有设置为flex,<code>flex-start将被视为start</code></dd>
<dt><code>flex-end</code></dt>
<dd>所有的子元素堆叠在父元素的主轴或交叉轴上终点对齐,主要取决于flex-direction的设置。<br>
仅适用于flex布局的子元素.。如果父元素没有设置为flex,<code>flex-end将被视为end</code></dd>
<dt><code>center</code></dt>
<dd>所有的子元素堆叠在父元素的中间对齐</dd>
<dt><code>left</code></dt>
<dd>The items are packed flush to each other toward the left edge of the alignment container. If the property’s axis is not parallel with the inline axis, this value behaves like <code>start</code>.</dd>
<dt><code>right</code></dt>
<dd>The items are packed flush to each other toward the right edge of the alignment container in the appropriate axis. If the property’s axis is not parallel with the inline axis, this value behaves like <code>start</code>.</dd>
<dt><code>space-between</code></dt>
<dd>The items are evenly distributed within the alignment container. The spacing between each pair of adjacent items is the same. The first item is flush with the main-start edge, and the last item is flush with the main-end edge.</dd>
<dt><code>baseline<br>
first baseline</code><br>
<code>last baseline</code></dt>
<dd>Specifies participation in first- or last-baseline alignment: aligns the alignment baseline of the box’s first or last baseline set with the corresponding baseline in the shared first or last baseline set of all the boxes in its baseline-sharing group.<br>
The fallback alignment for <code>first baseline</code> is <code>start</code>, the one for <code>last baseline</code> is <code>end</code>.</dd>
<dt><code>space-around</code></dt>
<dd>The items are evenly distributed within the alignment container. The spacing between each pair of adjacent items is the same. The empty space before the first and after the last item equals half of the space between each pair of adjacent items.</dd>
<dt><code>space-evenly</code></dt>
<dd>The items are evenly distributed within the alignment container. The spacing between each pair of adjacent items, the main-start edge and the first item, and the main-end edge and the last item, are all exactly the same.</dd>
<dt><code>stretch</code></dt>
<dd>If the combined size of the items is less than the size of the alignment container, any <code>auto</code>-sized items have their size increased equally (not proportionally), while still respecting the constraints imposed by {{CSSxRef("max-height")}}/{{CSSxRef("max-width")}} (or equivalent functionality), so that the combined size exactly fills the alignment container</dd>
</dl>
<h3 id="Formal_syntax">Formal syntax</h3>
{{CSSSyntax}}
<h2 id="举例">举例</h2>
<h3 id="CSS">CSS</h3>
<pre class="brush: css; highlight[7] notranslate">#container {
display: flex;
height:240px;
width: 240px;
flex-wrap: wrap;
background-color: #8c8c8c;
writing-mode: horizontal-tb; /* Can be changed in the live sample */
direction: ltr; /* Can be changed in the live sample */
place-content: flex-end center; /* Can be changed in the live sample */
}
div > div {
border: 2px solid #8c8c8c;
width: 50px;
background-color: #a0c8ff;
}
.small {
font-size: 12px;
height: 40px;
}
.large {
font-size: 14px;
height: 50px;
}
</pre>
<h3 id="HTML">HTML</h3>
<pre class="brush: html notranslate"><div id="container">
<div class="small">Lorem</div>
<div class="small">Lorem<br/>ipsum</div>
<div class="large">Lorem</div>
<div class="large">Lorem<br/>impsum</div>
<div class="large"></div>
<div class="large"></div>
</div>
</pre>
<div class="hidden">
<pre class="brush:html notranslate"><code>writing-mode:</code><select id="writingMode">
<option value="horizontal-tb" selected>horizontal-tb</option>
<option value="vertical-rl">vertical-rl</option>
<option value="vertical-lr">vertical-lr</option>
<option value="sideways-rl">sideways-rl</option>
<option value="sideways-lr">sideways-lr</option>
</select><code>;</code><br/>
<code>direction:</code><select id="direction">
<option value="ltr" selected>ltr</option>
<option value="rtl">rtl</option>
</select><code>;</code><br/>
<code>place-content:</code><select id="alignContentAlignment">
<option value="normal">normal</option>
<option value="first baseline">first baseline</option>
<option value="last baseline">last baseline</option>
<option value="baseline">baseline</option>
<option value="space-between">space-between</option>
<option value="space-around">space-around</option>
<option value="space-evenly" selected>space-evenly</option>
<option value="stretch">stretch</option>
<option value="center">center</option>
<option value="start">start</option>
<option value="end">end</option>
<option value="flex-start">flex-start</option>
<option value="flex-end">flex-end</option>
<option value="safe">safe</option>
<option value="unsafe">unsafe</option>
</select>
<select id="justifyContentAlignment">
<option value="normal">normal</option>
<option value="space-between">space-between</option>
<option value="space-around">space-around</option>
<option value="space-evenly">space-evenly</option>
<option value="stretch">stretch</option>
<option value="center" selected>center</option>
<option value="start">start</option>
<option value="end">end</option>
<option value="flex-start">flex-start</option>
<option value="flex-end">flex-end</option>
<option value="left">left</option>
<option value="right">right</option>
<option value="safe">safe</option>
<option value="unsafe">unsafe</option>
</select><code>;</code>
</pre>
<pre class="brush: js notranslate">var update = function () {
document.getElementById("container").style.placeContent = document.getElementById("alignContentAlignment").value + " " + document.getElementById("justifyContentAlignment").value;
}
var alignContentAlignment = document.getElementById("alignContentAlignment");
alignContentAlignment.addEventListener("change", update);
var justifyContentAlignment = document.getElementById("justifyContentAlignment");
justifyContentAlignment.addEventListener("change", update);
var writingM = document.getElementById("writingMode");
writingM.addEventListener("change", function (evt) {
document.getElementById("container").style.writingMode = evt.target.value;
});
var direction = document.getElementById("direction");
direction.addEventListener("change", function (evt) {
document.getElementById("container").style.direction = evt.target.value;
});
</pre>
</div>
<h3 id="Result">Result</h3>
<p>{{EmbedLiveSample("Example", "370", "300")}}</p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("CSS3 Box Alignment", "#propdef-place-content", "place content")}}</td>
<td>{{Spec2("CSS3 Box Alignment")}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<p>{{CSSInfo}}</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>{{Compat("css.properties.place-content")}}</div>
<h3 id="Support_in_Flex_layout">Support in Flex layout</h3>
<div>{{Compat("css.properties.place-content.flex_context")}}</div>
<h3 id="Support_in_Grid_layout">Support in Grid layout</h3>
<div>{{Compat("css.properties.place-content.grid_context")}}</div>
<h2 id="See_also">See also</h2>
<ul>
<li>CSS Flexbox Guide: <em><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox">Basic Concepts of Flexbox</a></em></li>
<li>CSS Flexbox Guide: <em><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Aligning_Items_in_a_Flex_Container">Aligning items in a flex container</a></em></li>
<li>CSS Grid Guide: <em><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Box_Alignment_in_CSS_Grid_Layout">Box alignment in CSS Grid layouts</a></em></li>
<li><a href="/en-US/docs/Web/CSS/CSS_Box_Alignment">CSS Box Alignment</a></li>
<li>The {{CSSxRef("align-content")}} property</li>
<li>The {{CSSxRef("justify-content")}} property</li>
</ul>
|