aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/justify-content
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/css/justify-content
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/css/justify-content')
-rw-r--r--files/zh-cn/web/css/justify-content/index.html359
1 files changed, 359 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/justify-content/index.html b/files/zh-cn/web/css/justify-content/index.html
new file mode 100644
index 0000000000..d06a19bbe5
--- /dev/null
+++ b/files/zh-cn/web/css/justify-content/index.html
@@ -0,0 +1,359 @@
+---
+title: justify-content
+slug: Web/CSS/justify-content
+tags:
+ - CSS
+ - CSS 属性
+ - CSS 弹性框
+ - Reference
+translation_of: Web/CSS/justify-content
+---
+<div>{{CSSRef}}</div>
+
+<p><a href="/zh-CN/docs/CSS" title="CSS">CSS</a> <strong><code>justify-content</code></strong> 属性定义了浏览器之间,如何分配顺着弹性容器主轴(或者网格行轴) 的元素之间及其周围的空间。</p>
+
+<pre class="brush: css notranslate"><code>/* Positional alignment */
+justify-content: center; </code>/* 居中排列 */<code>
+justify-content: start; /* Pack items from the start */
+justify-content: end; /* Pack items from the end */
+justify-content: flex-start; </code>/* 从行首起始位置开始排列 */<code>
+justify-content: flex-end; </code>/* 从行尾位置开始排列 */<code>
+justify-content: left; /* Pack items from the left */
+justify-content: right; /* Pack items from the right */</code>
+
+/* Baseline alignment */
+justify-content: baseline;
+justify-content: first baseline;
+justify-content: last baseline;
+
+/* Distributed alignment */
+justify-content: space-between; /* 均匀排列每个元素
+ 首个元素放置于起点,末尾元素放置于终点 */
+justify-content: space-around; /* 均匀排列每个元素
+ 每个元素周围分配相同的空间 */
+justify-content: space-evenly; /* 均匀排列每个元素
+ 每个元素之间的间隔相等 */
+justify-content: stretch; /* 均匀排列每个元素
+ 'auto'-sized 的元素会被拉伸以适应容器的大小 */
+
+/* Overflow alignment */
+justify-content: safe center;
+justify-content: unsafe center;
+
+/* Global values */
+justify-content: inherit;
+justify-content: initial;
+justify-content: unset;</pre>
+
+<p>当 length 属性和自动外边距属性(margin: auto)生效之后,对齐已经完成了。也就是说,如果存在至少一个弹性元素,而且这个元素的 {{cssxref("flex-grow")}} 属性不等于 0,那么对齐方式不会生效,就像没有多余空间的情况。 </p>
+
+<div>{{cssinfo}}</div>
+
+<div></div>
+
+<p>可以参考 <a href="/zh-CN/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes" title="CSS/Using_CSS_flexible_boxes"> 使用 CSS 弹性框</a>获取更多信息。</p>
+
+<h2 id="语法">语法</h2>
+
+<h3 id="值">值</h3>
+
+<dl>
+ <dt><code>start</code></dt>
+ <dd>从行首开始排列。每行第一个元素与行首对齐,同时所有后续的元素与前一个对齐。</dd>
+</dl>
+
+<dl>
+ <dt><code>flex-start</code></dt>
+ <dd>从行首开始排列。每行第一个弹性元素与行首对齐,同时所有后续的弹性元素与前一个对齐。</dd>
+ <dt><code>flex-end</code></dt>
+ <dd>从行尾开始排列。每行最后一个弹性元素与行尾对齐,其他元素将与后一个对齐。</dd>
+ <dt><code>center</code></dt>
+ <dd>伸缩元素向每行中点排列。每行第一个元素到行首的距离将与每行最后一个元素到行尾的距离相同。</dd>
+ <dt><code>left</code></dt>
+ <dd>伸缩元素一个挨一个在对齐容器得左边缘,如果属性的轴与内联轴不平行,则<code>left</code>的行为类似于<code>start</code>。</dd>
+ <dt><code>right</code></dt>
+ <dd>元素以容器右边缘为基准,一个挨着一个对齐,如果属性轴与内联轴不平行,则<code>right</code>的行为类似于<code>end</code>。</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-between</code></dt>
+ <dd>在每行上均匀分配弹性元素。相邻元素间距离相同。每行第一个元素与行首对齐,每行最后一个元素与行尾对齐。</dd>
+ <dt><code>space-around</code></dt>
+ <dd>在每行上均匀分配弹性元素。相邻元素间距离相同。每行第一个元素到行首的距离和每行最后一个元素到行尾的距离将会是相邻元素之间距离的一半。</dd>
+ <dt><code>space-evenly</code></dt>
+ <dd>flex项都沿着主轴均匀分布在指定的对齐容器中。相邻flex项之间的间距,主轴起始位置到第一个flex项的间距,,主轴结束位置到最后一个flex项的间距,都完全一样。</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 along the main axis.</dd>
+ <dt><code>safe</code></dt>
+ <dd>与对齐关键字一起使用,如果选定的关键字会导致元素溢出容器造成数据丢失,那么将会使用 <code>start</code> 代替它。</dd>
+ <dt><code>unsafe</code></dt>
+ <dd>Regardless of the relative sizes of the item and alignment container, the given alignment value is honored.</dd>
+</dl>
+
+<h3 id="语法格式">语法格式</h3>
+
+<pre class="syntaxbox notranslate">{{csssyntax}}
+</pre>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="CSS_content">CSS content</h3>
+
+<pre class="brush: css notranslate">#container {
+ display: flex;
+ justify-content: space-between; /* Can be changed in the live sample */
+}
+
+#container &gt; div {
+ width: 100px;
+ height: 100px;
+ background: linear-gradient(-45deg, #788cff, #b4c8ff);
+}
+</pre>
+
+<div class="hidden">
+<h3 id="HTML_content">HTML content</h3>
+
+<pre class="brush: html notranslate">&lt;div id="container"&gt;
+ &lt;div&gt;&lt;/div&gt;
+ &lt;div&gt;&lt;/div&gt;
+ &lt;div&gt;&lt;/div&gt;
+&lt;/div&gt;
+&lt;select id="justifyContent"&gt;
+ &lt;option value="start"&gt;start&lt;/option&gt;
+ &lt;option value="end"&gt;end&lt;/option&gt;
+ &lt;option value="flex-start"&gt;flex-start&lt;/option&gt;
+ &lt;option value="flex-end"&gt;flex-end&lt;/option&gt;
+ &lt;option value="center"&gt;center&lt;/option&gt;
+ &lt;option value="left"&gt;left&lt;/option&gt;
+ &lt;option value="right"&gt;right&lt;/option&gt;
+ &lt;option value="baseline"&gt;baseline&lt;/option&gt;
+ &lt;option value="first baseline"&gt;first baseline&lt;/option&gt;
+ &lt;option value="last baseline"&gt;last baseline&lt;/option&gt;
+ &lt;option value="space-between" selected&gt;space-between&lt;/option&gt;
+ &lt;option value="space-around"&gt;space-around&lt;/option&gt;
+ &lt;option value="space-evenly"&gt;space-evenly&lt;/option&gt;
+ &lt;option value="stretch"&gt;stretch&lt;/option&gt;
+&lt;/select&gt;</pre>
+
+<h3 id="JavaScript_content">JavaScript content</h3>
+
+<pre class="brush: js notranslate">var justifyContent = document.getElementById("justifyContent");
+justifyContent.addEventListener("change", function (evt) {
+ document.getElementById("container").style.justifyContent =
+ evt.target.value;
+});
+</pre>
+</div>
+
+<h3 id="Result">Result</h3>
+
+<p>{{EmbedLiveSample("Example", "100%", 140)}}</p>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th>Specification</th>
+ <th>Status</th>
+ <th>Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('CSS3 Box Alignment', '#propdef-justify-content', 'justify-content')}}</td>
+ <td>{{Spec2('CSS3 Box Alignment')}}</td>
+ <td>Adds the [ first | last ]? baseline, self-start, self-end, start, end, left, right, unsafe | safe values.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS3 Flexbox', '#propdef-justify-content', 'justify-content')}}</td>
+ <td>{{Spec2('CSS3 Flexbox')}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome(21.0)}} {{property_prefix("-webkit")}}<br>
+ {{CompatChrome(29.0)}}<sup>[3]</sup></td>
+ <td>{{CompatVersionUnknown}}{{property_prefix("-webkit")}}<br>
+ {{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop("18.0")}}<sup>[1]</sup><br>
+ {{CompatGeckoDesktop("20.0")}}<sup>[2]</sup></td>
+ <td>11</td>
+ <td>12.10</td>
+ <td>9</td>
+ </tr>
+ <tr>
+ <td><code>space-evenly</code></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop("52.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>start</code>, <code>end</code></td>
+ <td>{{CompatNo}}<sup>[4]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}<sup>[4]</sup></td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>left</code>, <code>right</code></td>
+ <td>{{CompatNo}}<sup>[4]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop("52.0")}}<sup>[5]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}<sup>[4]</sup></td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>baseline</code></td>
+ <td>{{CompatChrome("57.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatOpera("44.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>first baseline</code>, <code>last baseline</code></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop("52.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>stretch</code></td>
+ <td>{{CompatChrome("57.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop("52.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatOpera("44.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Android</th>
+ <th>Android Webview</th>
+ <th>Edge</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ <th>Chrome for Android</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}<sup>[3]</sup></td>
+ <td>{{CompatVersionUnknown}}{{property_prefix("-webkit")}}<br>
+ {{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>12.10</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}<sup>[3]</sup></td>
+ </tr>
+ <tr>
+ <td><code>space-evenly</code></td>
+ <td>{{CompatGeckoMobile("52.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>start</code>, <code>end</code></td>
+ <td>{{CompatNo}}<sup>[4]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}<sup>[4]</sup></td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>left</code>, <code>right</code></td>
+ <td>{{CompatNo}}<sup>[4]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoMobile("52.0")}}<sup>[5]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}<sup>[4]</sup></td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>baseline</code></td>
+ <td>{{CompatChrome("57.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatOpera("44.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>first baseline</code>, <code>last baseline</code></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoMobile("52.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>stretch</code></td>
+ <td>{{CompatChrome("57.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoMobile("52.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatOpera("44.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] 直到Firefox 28,Firefox都只支持单行弹性框。用户需要修改about:config,将“layout.css.flexbox.enabled”设置为“<code>true</code>”来在Firefox 18和19应用弹性框。</p>
+
+<p>[2] 比较旧的版本规范将绝对定位子项认为0 x 0 flex项。 后面的规范版本将它们从流程中取出并根据对齐和对齐属性设置它们的位置。 Chrome从Chrome 52开始的实施新行为。</p>
+
+<h2 id="参考">参考</h2>
+
+<ul>
+ <li><a href="/zh-CN/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes" title="CSS/Using_CSS_flexible_boxes">使用CSS弹性元素</a></li>
+</ul>