diff options
Diffstat (limited to 'files/zh-cn/web/css/grid-row')
-rw-r--r-- | files/zh-cn/web/css/grid-row/index.html | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/grid-row/index.html b/files/zh-cn/web/css/grid-row/index.html new file mode 100644 index 0000000000..d70f516ec5 --- /dev/null +++ b/files/zh-cn/web/css/grid-row/index.html @@ -0,0 +1,201 @@ +--- +title: grid-row +slug: Web/CSS/grid-row +tags: + - CSS + - CSS Grid + - CSS 网格 +translation_of: Web/CSS/grid-row +--- +<p><strong><code>grid-row</code></strong> 属性是一种 {{cssxref("grid-row-start")}} 和 {{cssxref("grid-row-end")}} 的缩写(<a href="/en-US/docs/Web/CSS/Shorthand_properties">shorthand</a>)形式,它定义了网格单元与网格行(row)相关的尺寸和位置,可以通过在网格布局中的基线(line),跨度(span),或者什么也不做(自动),从而指定 {{glossary("grid areas", "grid area")}} 的行起始与行结束。</p> + +<div>{{EmbedInteractiveExample("pages/css/grid-row.html")}}</div> + +<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div> + +<p>如果指定了两个 <grid-line> 值,那么斜杠号前的值就被指定为 <code>grid-row-start</code>,斜杠后面的值就被指定为 <code>grid-row-end</code> 的值。</p> + +<h2 id="语法">语法</h2> + +<pre class="brush: css no-line-numbers">/* 不同类型的属性值 */ +/* Keyword values */ +grid-row: auto; +grid-row: auto / auto; + +/* <custom-ident> values */ +grid-row: somegridarea; +grid-row: somegridarea / someothergridarea; + +/* <integer> + <custom-ident> values */ +grid-row: somegridarea 4; +grid-row: 4 somegridarea / 6; + +/* span + <integer> + <custom-ident> values */ +grid-row: span 3; +grid-row: span somegridarea; +grid-row: 5 somegridarea span; +grid-row: span 3 / 6; +grid-row: span somegridarea / span someothergridarea; +grid-row: 5 somegridarea span / 2 span; + +/* Global values */ +grid-row: inherit; +grid-row: initial; +grid-row: unset; +</pre> + +<h3 id="值">值</h3> + +<dl> + <dt><code>auto</code></dt> + <dd>表示对网格的布置行为不做干涉,即自动布置,自动的 span 或者默认 span 值为 1。</dd> + <dt><code><custom-ident></code></dt> + <dd>如果存在自定义的基线名('<custom-ident>-start'/'<custom-ident>-end'),它就将第一个这样的基线贡献给网格单元。 + <p class="note"><strong>注意:</strong> 被命名的网格区域(grid areas)会自动生成隐式的被命名的基线,因此指定 <code>grid-row: foo;</code> 将会选择这个命名区域的开始和结束的边界(除非在它之前存在显式指定的以 <code>foo-start</code>/<code>foo-end</code> 命名的其他基线)。</p> + + <p>否则,它就会被当作整数 <code>1</code> 与 <code><custom-ident></code> 一起指定。</p> + </dd> + <dt><code><integer> && <custom-ident>?</code></dt> + <dd>将第 n 条网格基线贡献给网格单元布置。如果指定的是负数,则指的是从下边界向上边界计算的反向顺序。如果提供的是<span style="font-size: 1rem; letter-spacing: -0.00278rem;"> <custom-ident>,那么只有以此命名的基线才会被计算。如果所命名的基线数超过了网格线数,为了找到该位置,所有隐式的网格线会被假定拥有这个命名。</span></dd> + <dd><span style="font-size: 1rem; letter-spacing: -0.00278rem;">{{cssxref("integer")}} 值不能为 </span><code style="font-size: 1rem; letter-spacing: -0.00278rem;">0</code><span style="font-size: 1rem; letter-spacing: -0.00278rem;">。</span></dd> + <dt><code>span && [ <integer> || <custom-ident> ]</code></dt> + <dd>为网格单元定义一个跨度,使得网格单元的网格区域中的一条边界远离另一条边界线 n 条基线。如果提供的是<span style="font-size: 1rem; letter-spacing: -0.00278rem;"> <custom-ident>,则只有以此命名的基线才会被计算。如果网格线不足,则</span>假定与搜索方向对应的显式网格一侧的所有隐式网格线都具有该名称。</dd> + <dd> + <p>如果忽略 <integer> ,它就默认设为 <code>1</code>。它的值也不能为0。</p> + </dd> +</dl> + +<h3 id="形式语法">形式语法</h3> + +<pre class="syntaxbox">{{csssyntax}}</pre> + +<h2 id="示例">示例</h2> + +<h3 id="HTML_Content">HTML Content</h3> + +<pre class="brush: html"><div id="grid"> + <div id="item1"></div> + <div id="item2"></div> + <div id="item3"></div> +</div></pre> + +<h3 id="CSS_Content">CSS Content</h3> + +<pre class="brush: css highlight[14,19]">#grid { + display: grid; + height: 200px; + grid-template-columns: 200px; + grid-template-rows: repeat(6, 1fr); +} + +#item1 { + background-color: lime; +} + +#item2 { + background-color: yellow; + grid-row: 2 / 4; +} + +#item3 { + background-color: blue; + grid-row: span 2 / 7; +} +</pre> + +<p>{{EmbedLiveSample("Example", "200px", "200px")}}</p> + +<h2 id="IE_中的问题">IE 中的问题</h2> + +<p>IE11 不支持网格单元的自动布置。除非显式地注释 <code>-ms-</code>{{cssxref("grid-column")}} 和 <code>-ms-</code>{{cssxref("grid-row")}},否则所有单元都会在网格的第一行/列结束。这里有一个使用 JavaScript 提供自动注释的工具:<a href="https://github.com/motine/css_grid_annotator">source repository</a>.</p> + +<h2 id="规范">规范</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 Grid", "#propdef-grid-row", "grid-row")}}</td> + <td>{{Spec2("CSS3 Grid")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<p>{{cssinfo}}</p> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("css.properties.grid-row")}}</p> + +<h2 id="参见">参见</h2> + +<ul> + <li>Related CSS properties: {{cssxref("grid-row-start")}}, {{cssxref("grid-row-end")}}, {{cssxref("grid-column")}}, {{cssxref("grid-column-start")}}, {{cssxref("grid-column-end")}}</li> + <li>Grid Layout Guide: <em><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Line-based_Placement_with_CSS_Grid">Line-based placement with CSS Grid</a></em></li> + <li>Video tutorial: <em><a href="http://gridbyexample.com/video/series-line-based-placement/">Line-based placement</a></em></li> +</ul> + +<section class="Quick_links" id="Quick_Links"> +<ol> + <li><a href="/en-US/docs/Web/CSS"><strong>CSS</strong></a></li> + <li><a href="/en-US/docs/Web/CSS/Reference"><strong>CSS Reference</strong></a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout">CSS Grid Layout</a></li> + <li data-default-state="open"><a href="#"><strong>Guides</strong></a> + <ol> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout">Basics concepts of grid layout</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Relationship_of_Grid_Layout">Relationship to other layout methods</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Line-based_Placement_with_CSS_Grid">Line-based placement</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Grid_Template_Areas">Grid template areas</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Layout_using_Named_Grid_Lines">Layout using named grid lines</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Auto-placement_in_CSS_Grid_Layout">Auto-placement in grid layout</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Box_Alignment_in_CSS_Grid_Layout">Box alignment in grid layout</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/CSS_Grid,_Logical_Values_and_Writing_Modes">Grids, logical values and writing modes</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/CSS_Grid_Layout_and_Accessibility">CSS Grid Layout and Accessibility</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/CSS_Grid_and_Progressive_Enhancement">CSS Grid Layout and Progressive Enhancement</a></li> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Realizing_common_layouts_using_CSS_Grid_Layout">Realizing common layouts using grids</a></li> + </ol> + </li> + <li data-default-state="open"><a href="#"><strong>Properties</strong></a> + <ol> + <li><a href="/en-US/docs/Web/CSS/grid">grid</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-area">grid-area</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-auto-columns">grid-auto-columns</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-auto-flow">grid-auto-flow</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-auto-rows">grid-auto-rows</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-column">grid-column</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-column-end">grid-column-end</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-column-gap">grid-column-gap</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-column-start">grid-column-start</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-gap">grid-gap</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-row">grid-row</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-row-end">grid-row-end</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-row-gap">grid-row-gap</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-row-start">grid-row-start</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-template">grid-template</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-template-areas">grid-template-areas</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-template-columns">grid-template-columns</a></li> + <li><a href="/en-US/docs/Web/CSS/grid-template-rows">grid-template-rows</a></li> + </ol> + </li> + <li data-default-state="open"><a href="#"><strong>Glossary</strong></a> + <ol> + <li><a href="/en-US/docs/Glossary/Grid_lines">Grid lines</a></li> + <li><a href="/en-US/docs/Glossary/Grid_tracks">Grid tracks</a></li> + <li><a href="/en-US/docs/Glossary/Grid_cell">Grid cell</a></li> + <li><a href="/en-US/docs/Glossary/Grid_areas">Grid areas</a></li> + <li><a href="/en-US/docs/Glossary/Gutters">Gutters</a></li> + <li><a href="/en-US/docs/Glossary/Grid_rows">Grid row</a></li> + <li><a href="/en-US/docs/Glossary/Grid_column">Grid column</a></li> + </ol> + </li> +</ol> +</section> |