CSS Grids教程学习笔记
<p>这是我在学习MDN内CSS Grids教程的学习笔记,教程地址:https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids</p><p><span style="font-size: 18px; color: rgba(255, 102, 0, 1)"><strong>注:这个笔记之能做温习只用,看教程请上以上地址学习或者其他教学资源。</strong></span></p>
<p> </p>
<p>容器上设置<strong>display: grid;</strong>就成为了grid容器。</p>
<p>Grid容器上设置:</p>
<p><strong>grid-template-column: 200px auto 1fr;</strong>可以设置各个列。<strong>1fr</strong>是占比,空间先被200px这样的固定宽度占用,剩下的再按各自fr的占比分配。</p>
<p><strong>grid-column-gap</strong>或<strong>column-gap</strong>设置列之间的间隔宽度,不能使用fr。</p>
<p><strong>grid-row-gap</strong>或<strong>row-gap</strong>设置行之间的间隔宽度,不能使用fr。</p>
<p><strong>grid-gap</strong>或<strong>gap</strong>可以同时设置行和列的间隔宽度,不能使用fr。 </p>
<p>grid-template-column: <strong>repeat(3, 1fr)</strong>可以设置三个各为1fr的列。</p>
<p>grid-template-columns: <strong>repeat(auto-fill, minmax(200px, 1fr))</strong>;可以设置列最小为200px,自动列数,有多余空间就使用掉。</p>
<p> </p>
<p>隐形grid和显性grid的区分:</p>
<p>隐形grid是指指定列,没有指定行数,宽度大小都是默认auto,当溢出时就变成和flexbox差不多一样的排列显示方式。</p>
<p>显性grid是指指定了列和行,使用<strong>grid-auto-rows</strong>和<strong>grid-auto-columns</strong>属性指定行和列的大小。</p>
<p> </p>
<p>Grid-auto-rows: <strong>minmax(100px, auto);</strong>可以设置行高最小100px,最大auto。</p>
<p> </p>
<p><span style="font-size: 16px">Grid元素上设置:</span></p>
<p> <strong>grid-column: 1 / 3;</strong>可以设为1到3列的横跨排布;-1为最后一列</p>
<p> <strong>grid-row: 2;</strong>可以设为在第二行的排布;-1为最后一行</p>
<p>grid-column-start,grid-column-end,grid-row-start,grid-row-end为以上的拆分。</p>
<p> </p>
<p><span style="font-size: 16px">以下属性放在grid容器上可以设置排布模板</span>(只能是矩形,可以使用点符号<span style="font-size: 18px"> <strong>.</strong> </span>来代替空白):</p>
<p><strong>grid-template-areas: </strong></p>
<p><strong> “header header”</strong></p>
<p><strong> “sidebar content”</strong></p>
<p><strong> “footer footer”;</strong></p>
<p>然后再各个grid元素上设置:<strong>grid-area: header;</strong>这样。</p>
<p> </p>
<p>Grid可以代替像bootstrap这样的框架,可以设置12列,以下是line-based的图:</p>
<p><img src="https://img2020.cnblogs.com/blog/1147685/202009/1147685-20200925111521715-1308296849.png" alt="" width="1372" height="837" loading="lazy"></p>
<p>如下代码设置每个grid元素的位置和占比。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 0, 1)">header </span>{<span style="color: rgba(255, 0, 0, 1)">
grid-column</span>:<span style="color: rgba(0, 0, 255, 1)"> 1 / 13</span>;<span style="color: rgba(255, 0, 0, 1)">
grid-row</span>:<span style="color: rgba(0, 0, 255, 1)"> 1</span>;
}<span style="color: rgba(128, 0, 0, 1)">
article </span>{<span style="color: rgba(255, 0, 0, 1)">
grid-column</span>:<span style="color: rgba(0, 0, 255, 1)"> 4 / 13</span>;<span style="color: rgba(255, 0, 0, 1)">
grid-row</span>:<span style="color: rgba(0, 0, 255, 1)"> 2</span>;
}<span style="color: rgba(128, 0, 0, 1)">
aside </span>{<span style="color: rgba(255, 0, 0, 1)">
grid-column</span>:<span style="color: rgba(0, 0, 255, 1)"> 1 / 4</span>;<span style="color: rgba(255, 0, 0, 1)">
grid-row</span>:<span style="color: rgba(0, 0, 255, 1)"> 2</span>;
}<span style="color: rgba(128, 0, 0, 1)">
footer </span>{<span style="color: rgba(255, 0, 0, 1)">
grid-column</span>:<span style="color: rgba(0, 0, 255, 1)"> 1 / 13</span>;<span style="color: rgba(255, 0, 0, 1)">
grid-row</span>:<span style="color: rgba(0, 0, 255, 1)"> 3</span>;
}</pre>
</div><br><br>
来源:https://www.cnblogs.com/yangzetaodecnblogs/p/13728939.html
頁:
[1]