diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/css/align-items/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/css/align-items/index.html')
-rw-r--r-- | files/zh-cn/web/css/align-items/index.html | 287 |
1 files changed, 287 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/align-items/index.html b/files/zh-cn/web/css/align-items/index.html new file mode 100644 index 0000000000..c534cc0d2b --- /dev/null +++ b/files/zh-cn/web/css/align-items/index.html @@ -0,0 +1,287 @@ +--- +title: align-items +slug: Web/CSS/align-items +tags: + - CSS + - CSS Flexible Boxes + - CSS 属性 + - 参考 +translation_of: Web/CSS/align-items +--- +<div>{{ CSSRef}}</div> + +<div></div> + +<p>CSS align-items属性将所有直接子节点上的align-self值设置为一个组。 align-self属性设置项目在其包含块中在交叉轴方向上的对齐方式。</p> + +<div>{{EmbedInteractiveExample("pages/css/align-items.html")}}</div> + + + +<p>目前,Flexbox和CSS网格布局支持此属性。在Flexbox中,它控制十字轴上项目的对齐方式,在网格布局中,它控制块轴上项目的对齐方式。</p> + +<h2 id="语法">语法</h2> + +<pre class="brush: css notranslate">/* Basic keywords */ +align-items: normal; +align-items: stretch; + +/* Positional alignment */ +align-items: center; /* Pack items around the center */ +align-items: start; /* Pack items from the start */ +align-items: end; /* Pack items from the end */ +align-items: flex-start; /* Pack flex items from the start */ +align-items: flex-end; /* Pack flex items from the end */ +align-items: self-start; +align-items: self-end; + +/* Baseline alignment */ +align-items: baseline; +align-items: first baseline; +align-items: last baseline; /* Overflow alignment (for positional alignment only) */ +align-items: safe center; +align-items: unsafe center; + +/* Global values */ +align-items: inherit; +align-items: initial; +align-items: unset;</pre> + +<h3 id="取值">取值</h3> + +<dl> + <dt><code>normal</code></dt> + <dd>这个关键字的效果取决于我们处在什么布局模式中: + <ul> + <li>在绝对定位的布局中,对于被替代的绝对定位盒子,这个效果和<code>start?</code>的效果的一样;对于其他所有绝对定位的盒子,这个效果和<code>stretch</code>的效果一样。 </li> + <li>在绝对定位布局的静态位置上,效果和<code>stretch</code>一样。</li> + <li>对于那些弹性项目而言,效果和<code>stretch</code>一样。</li> + <li>对于那些网格项目而言,效果和<code>stretch</code>一样,除了有部分比例或者一个固定大小的盒子的效果像<code>start</code>。</li> + <li>这个属性不适用于会计盒子和表格。</li> + </ul> + </dd> +</dl> + +<dl> + <dt><code>flex-start</code></dt> + <dd>元素向侧轴起点对齐。</dd> + <dt><code>flex-end</code></dt> + <dd>元素向侧轴终点对齐。</dd> + <dt><code>start</code></dt> + <dd>The item is packed flush to each other toward the start edge of the alignment container in the appropriate axis.</dd> + <dt><code>end</code></dt> + <dd>The item is packed flush to each other toward the end edge of the alignment container in the appropriate axis.</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>self-start</code></dt> + <dd>The items is packed flush to the edge of the alignment container of the start side of the item, in the appropriate axis.</dd> + <dt><code>self-end</code></dt> + <dd>The item is packed flush to the edge of the alignment container of the end side of the item, in the appropriate axis.</dd> + <dt><code>baseline</code></dt> + <dt><code>first baseline<br> + last baseline</code></dt> + <dd>所有元素向基线对齐。侧轴起点到元素基线距离最大的元素将会于侧轴起点对齐以确定基线。</dd> + <dt><code>stretch</code></dt> + <dd>弹性元素被在侧轴方向被拉伸到与容器相同的高度或宽度。</dd> + <dt><code>safe</code></dt> + <dd>Used alongside an alignment keyword. If the chosen keyword means that the item overflows the alignment container causing data loss, the item is instead aligned as if the alignment mode were <code>start</code>.</dd> + <dt><code>unsafe</code></dt> + <dd>Used alongside an alignment keyword. Regardless of the relative sizes of the item and alignment container and whether overflow which causes data loss might happen, the given alignment value is honored.</dd> + <dt> + <h3 id="语法格式">语法格式</h3> + </dt> +</dl> + +<pre class="syntaxbox notranslate">{{csssyntax}} +</pre> + +<h2 id="示例">示例</h2> + +<h3 id="CSS">CSS</h3> + +<pre class="brush: css; highlight[4] notranslate">#container { + height:200px; + width: 240px; + align-items: center; /* Can be changed in the live sample */ + background-color: #8c8c8c; +} + +.flex { + display: flex; + flex-wrap: wrap; +} + +.grid { + display: grid; + grid-template-columns: repeat(auto-fill, 50px); +} + +div > div { + box-sizing: border-box; + border: 2px solid #8c8c8c; + width: 50px; + display: flex; + align-items: center; + justify-content: center; +} + +#item1 { + background-color: #8cffa0; + min-height: 30px; +} + +#item2 { + background-color: #a0c8ff; + min-height: 50px; +} + +#item3 { + background-color: #ffa08c; + min-height: 40px; +} + +#item4 { + background-color: #ffff8c; + min-height: 60px; +} + +#item5 { + background-color: #ff8cff; + min-height: 70px; +} + +#item6 { + background-color: #8cffff; + min-height: 50px; + font-size: 30px; +} + +select { + font-size: 16px; +} + +.row { + margin-top: 10px; +}</pre> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html notranslate"><div id="container" class="flex"> + <div id="item1">1</div> + <div id="item2">2</div> + <div id="item3">3</div> + <div id="item4">4</div> + <div id="item5">5</div> + <div id="item6">6</div> +</div> + +<div class="row"> + <label for="display">display: </label> + <select id="display"> + <option value="flex">flex</option> + <option value="grid">grid</option> + </select> +</div> + +<div class="row"> + <label for="values">align-items: </label> + <select id="values"> + <option value="normal">normal</option> + <option value="flex-start">flex-start</option> + <option value="flex-end">flex-end</option> + <option value="center" selected>center</option> + <option value="baseline">baseline</option> + <option value="stretch">stretch</option> + + <option value="start">start</option> + <option value="end">end</option> + <option value="self-start">self-start</option> + <option value="self-end">self-end</option> + <option value="left">left</option> + <option value="right">right</option> + + <option value="first baseline">first baseline</option> + <option value="last baseline">last baseline</option> + + <option value="safe center">safe center</option> + <option value="unsafe center">unsafe center</option> + <option value="safe right">safe right</option> + <option value="unsafe right">unsafe right</option> + <option value="safe end">safe end</option> + <option value="unsafe end">unsafe end</option> + <option value="safe self-end">safe self-end</option> + <option value="unsafe self-end">unsafe self-end</option> + <option value="safe flex-end">safe flex-end</option> + <option value="unsafe flex-end">unsafe flex-end</option> + </select> +</div> +</pre> + +<div class="hidden"> +<h3 id="JavaScript">JavaScript</h3> + +<pre class="brush: js notranslate">var values = document.getElementById('values'); +var display = document.getElementById('display'); +var container = document.getElementById('container'); + +values.addEventListener('change', function (evt) { + container.style.alignItems = evt.target.value; +}); + +display.addEventListener('change', function (evt) { + container.className = evt.target.value; +}); +</pre> +</div> + +<h3 id="Result">Result</h3> + +<p>{{EmbedLiveSample("Examples", "260px", "290px")}}</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">说明</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS3 Box Alignment", "#propdef-align-items", "align-items")}}</td> + <td>{{Spec2("CSS3 Box Alignment")}}</td> + <td>Update to latest syntax definitions.</td> + </tr> + <tr> + <td>{{SpecName('CSS3 Flexbox', '#propdef-align-items', 'align-items')}}</td> + <td>{{Spec2('CSS3 Flexbox')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<p>{{cssinfo}}</p> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<h3 id="在弹性盒子布局中的兼容性">在弹性盒子布局中的兼容性</h3> + +<p>{{Compat("css.properties.align-items.flex_context")}}</p> + +<h3 id="在网格布局中的兼容性">在网格布局中的兼容性</h3> + +<p>{{Compat("css.properties.align-items.grid_context")}}</p> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li><a href="/en-US/docs/CSS/Using_CSS_flexible_boxes" title="/en-US/docs/CSS/Using_CSS_flexible_boxes">使用CSS弹性框</a></li> +</ul> |