多個class:
css中允許多個class:
<h1 class="green bold"> ... </h1>
严就。
選擇器:
Chaining Selectors:
舉例:如果同時有一個p元素和一個h1元素下都有一個class = uppercase
钮惠,那么可以通過在類名前添加它的父類來加以區(qū)分:
注意:兩個元素之間沒有空格蘸拔。(類似的拾稳,background-image: url(圖片地址)
胖腾,url和后面的括號之間也不能有空格)
h1.special {
}
嵌套元素:
<ul class='main-list'>
<li> ... </li>
<li> ... </li>
<li> ... </li>
</ul>
想要設(shè)置<li> ... </li>
的css樣式,可以通過嵌套元素的設(shè)置方法設(shè)置:
.main-list li {
}
一次選中多個選擇器媒役,并進(jìn)行css格式化:
h1 {
font-family: Georgia;
}
.menu {
font-family: Georgia;
}
同時選中:
h1,
.menu {
font-family: Georgia;
}
通過用逗號分隔.h1
和.menu
, 這兩個類都會被相應(yīng)的css格式修飾宪迟。
CSS 視覺規(guī)則:
CSS declarations are structured into property and value pairs.
CSS語句都是屬性和值相對應(yīng)的結(jié)構(gòu)酣衷。
font-family
定義了元素的字體。
font-size
控制文字顯示的大小次泽。
font-weight
定義文字的粗細(xì)程度穿仪。
text-align
屬性控制文字的對齊方式,可以取的分別為:left
, right
, center
意荤。
文字可以有兩種顏色屬性:前景色——color
和背景色——background-color
啊片。color
控制文字的顏色,background-color
控制文字的背景色玖像。
CSS中可以用opacity
屬性來令某個元素透明紫谷。
CSS中也可以通過 background-image
屬性來設(shè)置某個元素的背景為一張圖片。
盒模型:
border屬性:
除了顏色捐寥、邊框樣式笤昨、邊框大小之外,還可以調(diào)節(jié)邊框的圓角大小握恳,單位也是px
:
div.container {
height: 60px;
width: 60px;
border: 3px solid rgb(22, 77, 100);
border-radius: 100%;
}
padding屬性:
可以分別聲明padding-top瞒窒、padding-right、padding-bottom以及padding-left的值乡洼。
同時也可以直接聲明padding: 3px 4px 5 px 6px
崇裁,順序分別是上陵像、右、下寇壳、左。
使用上面這種寫法時妻怎,所有邊的padding數(shù)值都必須寫明壳炎。
不過,如果上下逼侦、左右的padding值是相等的匿辩,也可以寫作:
padding: 5px 10px
,這代表上下的padding都是5px榛丢,而左右的padding都是10px铲球。
margin屬性:
margin和padding類似,也有margin-top
晰赞、margin-right
稼病、margin-bottom
、margin-left
掖鱼。
同樣可以寫作
margin: 10px 20px 10px 2opx;
或者margin: 10px 20px;
然走,表示上下邊距為10px,左右邊距為20px戏挡。
margin的疊加有一點特殊:
水平方向的疊加就是簡單的數(shù)字疊加芍瑞。例如,如果左邊盒子margin-right = 10px;
褐墅,而右邊盒子的margin-left = 20px;
拆檬,那么這兩個盒子放置在一起時,他們交界處的margin= 10 + 20 = 30px;
妥凳。
而豎直方向的情況則有所不同竟贯,對于疊放的兩個盒子,如果上面盒子的margin-bottom = 30px;
逝钥,而下面盒子的margin-left = 20px;
澄耍,則交界處的margin值
為:30px。
利用margin實現(xiàn)居中對齊:
首先需要父元素有固定的width
或者height
晌缘。比如如果想要讓div1
實現(xiàn)橫向居中對齊齐莲,首先應(yīng)該設(shè)置其父元素div0
的width= 400px
,然后在css文件
中設(shè)置div1的margin值為:margin: 0 auto;
overflow:
被父元素包裹著的子元素可能會占據(jù)空間過大而超過父元素的容納范圍磷箕,此時可以通過設(shè)置overflow的值來進(jìn)行調(diào)整选酗。
overflow的值可以為:scroll
、hide
岳枷、display
芒填。
display屬性:
可以利用display
屬性來設(shè)置HTML元素的顯示方式呜叫。
可以設(shè)置為:none
, block
, inline-block
, inline
。
none
表示元素不顯示殿衰;
block
表示顯示為塊級元素朱庆;
inline
表示顯示為行內(nèi)元素;
inline-block
表示顯示為行內(nèi)塊級元素闷祥。
塊級元素和行內(nèi)塊級元素可以設(shè)置width
height
屬性娱颊,
而行內(nèi)元素則不能。
注:一旦給元素加上absolute或float就相當(dāng)于給元素加上了display:block;
凯砍。
position屬性:
- static
- fixed
- relative
- absolute
1. static屬性:
static是html元素的默認(rèn)position值箱硕,也就是按照正常的文檔流排列。
2. fixed屬性:
fixed的效果參見各種定在網(wǎng)頁上的廣告悟衩。
3. relative屬性:
relative的元素是相對于自己的default position來定位的剧罩。
<div class="first">第一塊</div>
<div class="second">第二塊</div>
<div class="third">第三塊</div>
<!--css文件-->
.first {
background-color: red;
color: white;
}
.second {
background-color: green;
color: white;
}
.third {
background-color: blue;
color: white;
}
3.1 默認(rèn)情況下:
3.2 當(dāng)設(shè)置第二塊div的position屬性為relative時:
.second {
background-color: green;
position: relative; //relative定位
color: white;
}
可以看到與默認(rèn)情況并無區(qū)別,
這是因為沒有指定目標(biāo)HTML元素相對其default position的偏移量座泳。
3.3 指定偏移量之后:
.second {
background-color: green;
position: relative;
color: white;
left: 20px;
top: 20px;
}
3.4 添加margin/padding值:
雖然單純地偏移并不會影響下面的第三塊div挑势,但是如果設(shè)置第二塊div的padding或margin值舰罚,還是會影響到第三塊div在文檔中的位置。
.second {
background-color: green;
position: relative;
color: white;
margin-bottom: 40px; //增加底部40px的margin薛耻,觀察div3的位置變化
padding-bottom: 10px; //增加底部10px的padding营罢,觀察div3的位置變化
left: 20px;
top: 20px;
}
4. absolute定位:
4.1 只設(shè)置position:absolute而不設(shè)置偏移量:
.first {
background-color: red;
color: white;
height: 40px; //為方便觀察,把div1的高度設(shè)為40px饼齿;
}
.second {
background-color: green;
color: white;
position: absolute; //設(shè)置div2的position: absolute;
}
.third {
background-color: blue;
color: white;
height: 40px; //為方便觀察饲漾,把div3的高度設(shè)為40px;
}
結(jié)果:
4.2 設(shè)置偏移量:
4.2.1只設(shè)置left偏移量:
.second {
background-color: green;
color: white;
position: absolute;
left: 40px; // 只設(shè)置left偏移40px
}
結(jié)果:
4.2.2同時設(shè)置left偏移量和top偏移量:
.second {
background-color: green;
color: white;
position: absolute;
left: 40px;
top: 10px; //同時設(shè)置left偏移量和top偏移量
}
結(jié)果:
事實上揉忘,absolute屬性就是要配合relative屬性使用才能更好發(fā)揮作用的:
例如跳座,想要在div3的任意位置顯示一個“發(fā)送”按鈕:
<div class="first">第一塊</div>
<div class="second">第二塊</div>
<div class="third">
第三塊
<input type="button" class="send-button" value= "發(fā)送">
</div>
.third {
background-color: blue;
color: white;
height: 40px;
position: relative; //relative定位
}
.send-button {
position: absolute; //absolute定位
}
設(shè)置“發(fā)送按鈕”的偏移量:
.send-button {
position: absolute;
top: 20px;
left: 80px;
}
結(jié)果:
float:
通過float屬性疲眷,可以使HTML元素脫離正常的文檔流禾蚕,豎直方向上將不再占用文檔的空間,不過水平方向上不變狂丝。
比如可以利用這一特性换淆,讓序列橫向排列:
HTML文件:
<div class="backPanel">
<li>
<ul class="floated">語文</ul>
<ul class="floated">英語</ul>
<ul class="floated">數(shù)學(xué)</ul>
</li>
</div>
CSS文件:
.backPanel {
background-color: gray;
padding: 10px;
}
默認(rèn)情況下的結(jié)果:
利用float屬性來ul元素橫向排列:
.backPanel {
background-color: gray;
padding: 10px;
}
li {
list-style: none; //去掉了無序列表的小黑點
}
.floated {
width: 29%;
padding: 1%;
margin: 1%;
text-align: center;
background-color: white; //以上稍微調(diào)整了一下ul元素的樣式
float: left; // 設(shè)置ul元素向左浮動
}
結(jié)果:
此時只需要設(shè)置一下backPanel的height即可:
.backPanel {
background-color: gray;
padding: 10px;
height: 80px; //看起來是包住了魂奥,其實是鋪在下面了
}
float屬性雖然在豎直方向上不占空間了菠剩,但不會脫離文檔流:
<p>"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<li>
<ul class="floated">語文</ul>
<ul class="floated">英語</ul>
<ul class="floated">數(shù)學(xué)</ul>
</li>
li {
list-style: none;
}
.floated {
width: 29%;
padding: 1%;
margin: 1%;
text-align: center;
background-color: black;
color: white;
float: left;
}
比如現(xiàn)在ul元素
都沒有父元素包裹了,上面只有一個<p> </p>
元素耻煤,float之后的ul元素
并不會“飛到”文檔頂端去:
顏色值(color):
css中的color從類型上可以分為color (前景色)
和background-color
:
<h1>H1</h1>
h1 {
color: white; //前景色
background-color: black; //背景色
}
效果:
css中的color從表現(xiàn)方式上可以分為三種:
-
十六進(jìn)制
表示法哈蝇; -
rgb
表示法(還可以拓展為rgba
表示法棺妓,a
表示alpha
,指的是opacity
——不透明度)炮赦; -
hsl
表示法(還可以拓展為hsla
表示法怜跑,a
同上)。
舉例:
<div class="hex">hex</div>
<div class="rgb">rgb</div>
<div class="rgba">rgba</div>
<div class="hsl">hsl</div>
<div class="hsla">hsla</div>
.hex {
background-color: #FFAA00;
height: 80px;
width: 80px;
}
.rgb{
background-color: rgb(222, 22, 2);
height: 80px;
width: 80px;
}
.rgba {
background-color: rgba(222, 22, 2, 0.2);
height: 80px;
width: 80px;
}
.hsl {
background-color: hsl(180, 60%, 90%); //注意百分號
height: 80px;
width: 80px;
}
.hsla {
background-color: hsla(180, 60%, 90%, 0.4);
height: 80px;
width: 80px;
}
結(jié)果:
附上各種能叫得名字來的顏色值:有名字的顏色值吠勘。
排版:
設(shè)置字體:
font-family: 字體名稱;
設(shè)置字體權(quán)重:
font-weight: bold | normal;
也可以用數(shù)值來表示性芬,數(shù)值的范圍為[100, 900]且必須是100的整數(shù)倍。
- 400 is the
default
font-weight of most text. - 700 signifies a
bold
font-weight. - 300 signifies a
light
font-weight.
舉例:
<span class="default">中</span>
<span class="bold">中</span>
<span class="light">中</span>
.default {
font-weight: 400;
}
.bold{
font-weight: 700;
}
.light{
font-weight:300;
}
It's important to note that not all fonts can be assigned a numeric font-weight. You can look up the font you are using to see which font-weight values are available.
設(shè)置字體風(fēng)格:
font-style: italic;
——斜體剧防;
設(shè)置文字大小寫:
text-transform: uppercase | lowercase;
設(shè)置文字對齊方式:
text-align: left | right | center;
設(shè)置行高:
Another property that we can set for text is
line-height
. This property modifies theleading
of text.
The diagram beneath helps illustrate exactly what the terms "leading" and "line height" mean.
舉例:
p {
line-height: 1.4;
}
后備字體(fallback fonts):
h1 {
font-family: "Garamond", "Times", serif;
}
以上CSS語句的意思是:
- 對網(wǎng)頁上所有的
<h1>元素
優(yōu)先使用Garamond 字體
植锉; - 如果Garamond 字體不存在,那么就用
Times 字體
峭拘; - 如果以上兩種字體在目標(biāo)客戶端上都沒有俊庇,那么就使用該客戶端上存在的任意一種
襯線字體(serif)
。
注:
相對應(yīng)地鸡挠,也存在非襯線字體
:sans-serif
fonts;
CSS 網(wǎng)格(grid):
創(chuàng)建網(wǎng)格:
.grid {
width: 1080px;
height: 500px;
display: grid;
}
定義網(wǎng)格列grid-template-columns:px | %;
.grid {
display: grid;
width: 1000px;
height: 500px;
grid-template-columns: 100px 200px;
}
grid-template-columns: 100px 200px;
的意思是:將此網(wǎng)格分為兩列辉饱。
其中,第一列的width = 100px拣展,第二列的width = 200px鞋囊。
寬度的單位也可以不是px
,可以用百分?jǐn)?shù)
表示:
.grid {
display: grid;
width: 1000px;
grid-template-columns: 20% 50%;
}
上面grid的寬度是1000px瞎惫, 所以第一列的寬度是1000 * 20% = 200px溜腐;同理译株,第二列的寬度是500px。
也可以混用px
和%
:
.grid {
border: 1px solid black; //給grid一個邊框以更好地表現(xiàn) 其中的元素會超出grid的界限
display: grid;
width: 100px;
grid-template-columns: 20px 40% 60px; // 也可以混用`px`和`%`
}
.item {
background-color: gray;
}
這3列中挺益,第一列width為20px歉糜,第二列為100 * 40% = 40px,第三列width為60px望众。
注意:也就是說匪补,總寬度20 + 40 + 60 = 120px,超過了100px烂翰,元素會超出grid的界限夯缺。
定義網(wǎng)格行grid-template-rows: px | %;
與定義grid columns
是類似的:
<div class="grid">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
<div class="item">E</div>
<div class="item">F</div>
<div class="item">G</div>
<div class="item">H</div>
<div class="item">I</div>
<div class="item">J</div>
<div class="item">K</div>
</div>
.grid {
border: 1px solid black;
display: grid;
width: 1000x;
height: 400px;
grid-template-rows: 25% 25% 25% 25%;
grid-template-columns: 25% 25% 25% 25%;
}
.item {
background-color: gray;
margin: 2px;
text-align: center;
}
結(jié)果:
一句話定義grid的行和列:
<div class="grid">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
<div class="item">E</div>
<div class="item">F</div>
<div class="item">G</div>
<div class="item">H</div>
<div class="item">I</div>
<div class="item">J</div>
<div class="item">K</div>
</div>
.grid {
display: grid;
width: 600px;
height: 500px;
grid-template: 200px 300px / 20% 10% 70%; //斜杠前面定義“行”踊兜, 后面定義“列”
//200px 300px兩行,一行高200px佳恬,第二行高300px捏境;
//20% 10% 70% 表示3列,第一列寬500 * 20% = 50px毁葱;第二垫言、三列類似。
}
.item {
background-color: gray;
margin: 2px;
text-align: center;
}
結(jié)果:
fraction (fr):
通過單位fr
倾剿,我們可以將行和列定義為對grid的length和width的劃分——作用類似于%
筷频,但是用%
是有超出父容器邊界的風(fēng)險的,而用fr
則不用擔(dān)心前痘,因為瀏覽器會自動對grid進(jìn)行劃分截驮。
<div class="grid">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
<div class="item">E</div>
<div class="item">F</div>
<div class="item">G</div>
<div class="item">H</div>
<div class="item">I</div>
</div>
.grid {
display: grid;
float: left;
margin-right: 10px;
border: 1px solid black;
width: 500px;
height: 400px;
grid-gap: 20px 5px;
grid-template: 2fr 1fr 1fr / 1fr 3fr 1fr; //fr的作用
}
這樣做的優(yōu)點就是相對于
%
不用進(jìn)行繁瑣的計算,且可以確保grid中的item不會超出邊界乖菱。即使是橫向只用
fr
定義了3行坡锡,而實際的數(shù)據(jù)有5行,也依然不會造成item出界窒所。下面做一個對比:
<div class="grid">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
<div class="item">E</div>
<div class="item">F</div>
<div class="item">G</div>
<div class="item">H</div>
<div class="item">I</div>
<div class="item">J</div>
<div class="item">K</div>
<div class="item">L</div>
<div class="item">M</div>
<div class="item">N</div>
<div class="item">O</div>
<div class="item">P</div>
<div class="item">Q</div>
</div>
<div class="next-grid">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
<div class="item">E</div>
<div class="item">F</div>
<div class="item">G</div>
<div class="item">H</div>
<div class="item">I</div>
</div>
.grid {
display: grid;
float: left;
margin-right: 10px;
border: 1px solid black;
width: 500px;
height: 400px;
grid-gap: 20px 5px;
grid-template: 2fr 1fr 1fr / 1fr 3fr 1fr;
}
.next-grid {
float: left;
display: grid;
border: 1px solid black;
width: 500px;
height: 400px;
grid-gap: 20px 5px;
grid-template: 2fr 1fr 1fr / 1fr 3fr 1fr;
}
.item {
background-color: gray;
text-align: center;
}
repeat()函數(shù):
如果行高或列寬相等革屠,可以用repeat()
函數(shù)來簡化語句:
.grid {
display: grid;
float: left;
margin-right: 10px;
border: 1px solid black;
width: 500px;
height: 400px;
grid-gap: 20px 5px;
grid-template-columns: repeat(4, 1fr); //豎直方向等寬的4列
grid-template-rows: repeat(3, 1fr); //水平方向等高的3行
}
.item {
background-color: gray;
text-align: center;
}
結(jié)果:
注:
repeat()后面的
fr
并不是只能有一個:
## minmax函數(shù):
假設(shè)有3列狠裹,第一列和第三列的列寬都是100px,當(dāng)瀏覽器的寬度變化時漓穿,想要讓中間的那一列的列寬在100px~500px之間變化悠反,則可以設(shè)置:
.grid {
display: grid;
grid-template-columns: 100px minmax(100px, 500px) 100px;
}
.grid {
display: grid;
float: left;
margin-right: 10px;
border: 1px solid black;
width: 500px;
height: 400px;
grid-gap: 20px 5px;
grid-template-rows: repeat(4, 1fr 2fr); //一共8行残黑,(1fr + 2fr)的樣式重復(fù)4次。
grid-template-columns: repeat(3, 1fr 2fr);
}
結(jié)果:
設(shè)置行間距斋否、列間距梨水,同時設(shè)置行、列間距:
.grid {
display: grid;
width: 320px;
grid-template-columns: repeat(3, 1fr); //等寬的3列
grid-column-gap: 10px; //列間距
}
行間距同理:
grid-row-gap: 10px;
同時設(shè)置行茵臭、列間距:
grid-gap: 20px 10px;
—— 一句話疫诽,分別設(shè)置行間距為20px,列間距為10px笼恰。
注:
It is important to note that grid-gap does not add space at the beginning or end of the grid.
這一簡寫形式并不需要/
踊沸,如果只提供了一個值歇终,比如:grid-gap: 10px;
社证,則相當(dāng)于grid-gap: 10px 10px;
。
以上都是針對grid本身的评凝,以下語法則是針對grid的item的:
設(shè)置item跨行 grid-row-start: 5; grid-row-end: 7;
:
.grid {
display: grid;
border: 2px blue solid;
height: 500px;
width: 500px;
grid-template: repeat(4, 1fr 2fr) / repeat(4, 3fr 2fr);
grid-gap: 5px;
}
.a {
grid-row-start: 5; //設(shè)置這個item的起始行是第5行
grid-row-end: 7; //設(shè)置這個item在跨第5追葡、6行,不跨第7行——終止于第7行之前
}
.box {
background-color: beige;
color: black;
border-radius: 5px;
border: 2px dodgerblue solid;
}
簡寫形式:
.a {
grid-row: 5 / 7;
}
同理奕短,
設(shè)置item跨列:
.item {
grid-column-start: 4;
grid-column-end: 6;
}
同樣宜肉,也可以寫作:
.item {
grid-column: 4 /6;
}
利用span
屬性來避免“誤差”:
span
可以明確地指出希望行或列跨越的距離:
比如,如果想要row從第4行開始翎碑,占兩行谬返,就可以直接寫作:
.item {
grid-row: 4 / span 6;
}
不用grid-row
的簡寫形式,也可以寫作:
.item {
grid-row-start: 4;
grid-row-end: span 2;
}
當(dāng)然日杈,span
也可以用在grid-row-start
之后遣铝,瀏覽器會自動為我們計算出結(jié)果:
.b {
grid-row-start: span 3;
grid-row-end: 3;
}
結(jié)果:
對于
grid-column
莉擒,span的用法是完全相同的酿炸,不再贅述。
網(wǎng)格區(qū)域(grid area):
可以用一句話聲明一個item占grid的多少行涨冀、列填硕,并限定它在grid中的具體位置。
.b {
grid-area: 2 / 3 / span 2 / span 4;
}
結(jié)果:
CSS網(wǎng)格進(jìn)階屬性:
Grid Template Areas:
利用這個屬性,可以先做出一個模板恋拍,然后讓各個元素分別去“認(rèn)領(lǐng)”他們所占的行和列垛孔。
<div class="container">
<header>Welcome!</header>
<nav>Links!</nav>
<section class="info">Info!</section>
<section class="services">Services!</section>
<footer>Contact us!</footer>
</div>
比如container
下面有5個板塊:
.container {
display: grid;
max-width: 900px;
position: relative;
margin: auto;
grid-template-areas: "head head"
"nav nav"
"info services"
"footer footer";
grid-template-rows: 300px 120px 800px 120px;
grid-template-columns: 1fr 3fr;
}
先用
grid-template-areas
屬性“打好格子",然后各部分元素再利用grid-area
屬性將自己“代入”打好的格子中:
header {
grid-area: head;
}
nav {
grid-area: nav;
}
.info {
grid-area: info;
}
.services {
grid-area: services;
}
footer {
grid-area: footer;
}
注:
圖中的grid是四行兩列的,當(dāng)header 和 header并列時施敢,表示header占兩列周荐,此時header將占據(jù)整行,即使存在grid gap僵娃,依然不會將兩個header分隔開概作。虛線只是為了便于理解,實際并不存在默怨。
justify-items:
設(shè)置grid元素在每個格子中水平方向上的對齊方式讯榕。
justify-items
屬性可以接收的值為:
- start
- end
- end
- strench
注:這個屬性是container中的,而不是每個item的匙睹。
align-items:
設(shè)置grid元素在每個格子中豎直方向上的對齊方式:
同樣可以接收以下值:
- start
- end
- end
- strench
注:這個屬性是container中的愚屁,而不是每個item的。
justify-content:
設(shè)置整個grid在其父容器中痕檬,水平方向上的對齊方式:
可以取的值為:
屬性取值 | 效果 |
---|---|
start | aligns the grid to the left side of the grid container |
end | aligns the grid to the right side of the grid container |
center | centers the grid horizontally in the grid container |
stretch | stretches the grid items to increase the size of the grid to expand horizontally across the container |
space-around | includes an equal amount of space on each side of a grid element, resulting in double the amount of space between elements as there is before the first and after the last element |
space-between | includes an equal amount of space between grid items and no space at either end |
space-evenly | places an even amount of space between grid items and at either end |
main {
display: grid;
width: 1000px;
grid-template-columns: 300px 300px;
grid-template-areas: "left right";
justify-content: center;
}
align-content:
同理,利用align-content
屬性可以設(shè)置整個grid在其父容器中梦谜,豎直方向上的對齊方式丘跌。
原理均與justify-content
屬性相似,不再贅述唁桩。
Justify Self and Align Self:
利用justify-self
闭树、align-self
屬性,可以分別設(shè)置grid的每個格子中荒澡,具體某個item在水平报辱、豎直方向上的對齊方式。
屬性可以取的四種值 | 效果 |
---|---|
start | positions grid items on the left side/top of the grid area |
end | positions grid items on the right side/bottom of the grid area |
center | positions grid items on the center of the grid area |
stretch | positions grid items to fill the grid area (default) |