diff options
Diffstat (limited to 'files/zh-cn/web/css/grid-template-rows/index.html')
-rw-r--r-- | files/zh-cn/web/css/grid-template-rows/index.html | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/grid-template-rows/index.html b/files/zh-cn/web/css/grid-template-rows/index.html new file mode 100644 index 0000000000..a898da47be --- /dev/null +++ b/files/zh-cn/web/css/grid-template-rows/index.html @@ -0,0 +1,210 @@ +--- +title: grid-template-rows +slug: Web/CSS/grid-template-rows +tags: + - grid-template-rows +translation_of: Web/CSS/grid-template-rows +original_slug: Web/CSS/网格-模板-列 +--- +<p><code>grid-template-rows</code> 该属性是基于 {{glossary("grid rows", "网格行")}} 的维度,去定义网格线的名称和网格轨道的尺寸大小。</p> + +<div>{{EmbedInteractiveExample("pages/css/grid-template-rows.html")}}</div> + + + +<h2 id="语法">语法</h2> + +<pre class="brush: css no-line-numbers">/* Keyword value */ +grid-template-rows: none; + +/* <track-list> values */ +grid-template-rows: 100px 1fr; +grid-template-rows: [linename] 100px; +grid-template-rows: [linename1] 100px [linename2 linename3]; +grid-template-rows: minmax(100px, 1fr); +grid-template-rows: fit-content(40%); +grid-template-rows: repeat(3, 200px); + +/* <auto-track-list> values */ +grid-template-rows: 200px repeat(auto-fill, 100px) 300px; +grid-template-rows: minmax(100px, max-content) + repeat(auto-fill, 200px) 20%; +grid-template-rows: [linename1] 100px [linename2] + repeat(auto-fit, [linename3 linename4] 300px) + 100px; +grid-template-rows: [linename1 linename2] 100px + repeat(auto-fit, [linename1] 300px) [linename3]; + +/* Global values */ +grid-template-rows: inherit; +grid-template-rows: initial; +grid-template-rows: unset; +</pre> + +<p>该属性可能包含如下值:</p> + +<ul> + <li>关键字 <code>none</code></li> + <li>或者 <code><track-list></code> 值</li> + <li>或者 <code><auto-track-list></code> 值。</li> +</ul> + +<h3 id="值">值</h3> + +<dl> + <dt><code>none</code></dt> + <dd>这个关键字表示不明确的网格。所有的行和其大小都将由{{cssxref("grid-auto-rows")}} 属性隐式的指定。</dd> + <dt>{{cssxref("<length>")}}</dt> + <dd>非负值的长度大小。</dd> + <dt>{{cssxref("<percentage>")}}</dt> + <dd>非负值且相对于网格容器的 {{cssxref("percentage", "<百分比>")}}。 如果网格容器的尺寸大小依赖网格轨道的大小(比如 <font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">inline-grid</span></font> ),则百分比值将被视为<code>auto</code>。</dd> + <dd>为了遵守网格的百分比,网格轨道本身定义的大小,将自动被调整为相对网格容器大小,并且是以最小量将网格轨道调整到最终的大小。</dd> + <dt>{{cssxref("<flex_value>","<flex>")}}</dt> + <dd>非负值,用单位 <code>fr</code> 来定义网格轨道大小的弹性系数。 每个定义了 <code><flex></code> 的网格轨道会按比例分配剩余的可用空间。当外层用一个 <code>minmax()</code> 表示时,它将是一个自动最小值(即 <code>minmax(auto, <flex>)</code> ) 。</dd> + <dt><code>max-content</code></dt> + <dd>是一个用来表示以网格项的最大的内容来占据网格轨道的关键字。</dd> + <dt><code>min-content</code></dt> + <dd>是一个用来表示以网格项的最大的最小内容来占据网格轨道的关键字。</dd> + <dt>{{cssxref("minmax", "minmax(min, max)")}}</dt> + <dd>是一个来定义大小范围的属性,大于等于min值,并且小于等于max值。如果max值小于min值,则该值会被视为min值。最大值可以设置为网格轨道系数值<code><flex></code> ,但最小值则不行。 </dd> + <dd> + <p class="note">Note: 该规范在将来可能会允许设置最小值为 <code>flex</code> ,也会调整网格轨道算法(<a href="https://www.w3.org/TR/css-grid-1/#track-sizing-algorithm">track sizing algorithm</a>) 计算出正确的大小。</p> + </dd> + <dt><code>auto</code></dt> + <dd>如果该网格轨道为最大时,该属性等同于 <code><max-content></code> ,为最小时,则等同于 <code><min-content></code> 。</dd> + <dd> + <p class="note">Note: 网格轨道大小为 <code>auto</code> (且只有为 <code>auto</code> ) 时,才可以被属性{{cssxref("align-content")}} 和 {{cssxref("justify-content")}} 拉伸 。</p> + </dd> + <dt>{{cssxref("fit-content", "fit-content( [ <length> | <percentage> ] )")}}</dt> + <dd>相当于公式 <code>min(max-content, max(auto, <var>argument</var>))</code>,类似于<code>auto</code> 的计算(即 <code>minmax(auto, max-content)</code>),除了网格轨道大小值是确定下来的,否则该值都大于 <code>auto</code> 的最小值。</dd> + <dt>{{cssxref("repeat", "repeat( [ <positive-integer> | auto-fill | auto-fit ] , <track-list> )")}}</dt> + <dd>表示网格轨道的重复部分,以一种更简洁的方式去表示大量而且重复行的表达式。</dd> +</dl> + +<h3 id="正式语法">正式语法</h3> + +<pre>{{csssyntax}}</pre> + +<h2 id="示例">示例</h2> + +<h3 id="CSS">CSS</h3> + +<pre class="brush:css">#grid { + display: grid; + height: 100px; + grid-template-rows: 30px 1fr; +} + +#areaA { + background-color: lime; +} + +#areaB { + background-color: yellow; +}</pre> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"><div id="grid"> + <div id="areaA">A</div> + <div id="areaB">B</div> +</div></pre> + +<h3 id="结果">结果</h3> + +<p>{{EmbedLiveSample("示例", "40px", "100px")}}</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 Grid", "#propdef-grid-template-rows", "grid-template-rows")}}</td> + <td>{{Spec2("CSS3 Grid")}}</td> + <td>初步定义</td> + </tr> + </tbody> +</table> + +<p>{{cssinfo}}</p> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p> </p> + + + +<p>{{Compat("css.properties.grid-template-rows")}}</p> + +<p> </p> + +<h2 id="参见">参见</h2> + +<ul> + <li>相关CSS属性: {{cssxref("grid-template-columns")}}, {{cssxref("grid-template-areas")}}, {{cssxref("grid-template")}}</li> + <li>网格布局指南: <em><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout#Grid_Tracks">Basic concepts of grid layout - Grid Tracks</a></em></li> + <li>视频教程: <em><a href="http://gridbyexample.com/video/series-define-a-grid/">Defining a Grid</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> |