自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

面試官讓我用 Flex 寫(xiě)色子布局,我直接寫(xiě)了六種

開(kāi)發(fā) 前端
面試中經(jīng)常會(huì)被問(wèn)道前端布局的實(shí)現(xiàn),最典型的就是使用Flex實(shí)現(xiàn)色子的布局,這篇文章會(huì)逐步的介紹如何使用Flex實(shí)現(xiàn)色子的各個(gè)點(diǎn)數(shù)的布局。

復(fù)習(xí)一下Flex布局屬性

在實(shí)現(xiàn)色子布局之前,我們先來(lái)復(fù)習(xí)一下這幾個(gè)Flex布局的屬性:

justify-content:用于調(diào)整元素在主軸的對(duì)其方式;

align-items:用于調(diào)整元素在側(cè)軸的對(duì)其方式;

align-self:設(shè)置元素自身在側(cè)軸的對(duì)齊方式;

flex-direction:定義主軸是水平還是垂直或者正反方向。

多說(shuō)無(wú)益,我們直接來(lái)寫(xiě)代碼

實(shí)現(xiàn)一點(diǎn)布局

實(shí)現(xiàn)一點(diǎn)布局就非常簡(jiǎn)單了,可以說(shuō)就是一個(gè)水平垂直居中 ,用flex布局實(shí)現(xiàn)相當(dāng)?shù)娜菀祝瑢?shí)現(xiàn)代碼如下:

html

<body>
<div class="warp">
<div class="pip"></div>
</div>
</body>
復(fù)制代碼

css

<style>
.warp {
display: flex;
/* 實(shí)現(xiàn) 一點(diǎn) 布局 */
justify-content: center;
align-items: center;
}
</style>
復(fù)制代碼

這里只貼出核心代碼,剩余代碼就是一些樣式樣的調(diào)整。

實(shí)現(xiàn)效果如下:

圖片

這里我們用到了justify-content和align-items,就輕松的實(shí)現(xiàn)了色子的一點(diǎn)布局。

實(shí)現(xiàn)二點(diǎn)布局

現(xiàn)在我們實(shí)現(xiàn)色子的二點(diǎn)布局,實(shí)現(xiàn)代碼如下:

html

<body>
<div class="warp">
<div class="column"><div class="pip"></div></div>
<div class="column"><div class="pip"></div></div>
</div>
</body>
復(fù)制代碼

css

<style>
.warp {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.column {
display: flex;
}
.column:nth-child(2) {
justify-content: flex-end;
}
</style>
復(fù)制代碼

這僅僅是實(shí)現(xiàn)的一種方案,還有別的寫(xiě)法。

圖片

實(shí)現(xiàn)三點(diǎn)布局

三點(diǎn)布局與二點(diǎn)布局類(lèi)似,只需要再添加一行即可,實(shí)現(xiàn)代碼如下:

html

<body>
<div class="warp">
<div class="column"><div class="pip"></div></div>
<div class="column"><div class="pip"></div></div>
<div class="column"><div class="pip"></div></div>
</div>
</body>
復(fù)制代碼

css

<style>
.warp {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.column {
display: flex;
}
.column:nth-child(2) {
justify-content: center;
}
.column:nth-child(3) {
justify-content: flex-end;
}
</style>
復(fù)制代碼

運(yùn)行效果如下:

圖片

實(shí)現(xiàn)四點(diǎn)布局

四點(diǎn)布局可以說(shuō)是二點(diǎn)布局的變種,實(shí)現(xiàn)代碼如下:

html

<body>
<div class="warp">
<div class="column">
<div class="pip"></div>
<div class="pip"></div>
</div>
<div class="column">
<div class="pip"></div>
<div class="pip"></div>
</div>
</div>
</body>
復(fù)制代碼

css

.warp {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.column {
display: flex;
justify-content: space-between;
}
復(fù)制代碼

運(yùn)行效果如下:

圖片

實(shí)現(xiàn)五點(diǎn)布局

實(shí)現(xiàn)五點(diǎn)布局可以在四點(diǎn)布局的基礎(chǔ)上增加一行,示例代碼如下:

html

<body>
<div class="warp">
<div class="column">
<div class="pip"></div>
<div class="pip"></div>
</div>
<div class="column">
<div class="pip"></div>
</div>
<div class="column">
<div class="pip"></div>
<div class="pip"></div>
</div>
</div>
</body>
復(fù)制代碼

css

.warp {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.column {
display: flex;
justify-content: space-between;
}
.column:nth-child(2) {
justify-content: center;
}
復(fù)制代碼

運(yùn)行效果如下:

圖片

實(shí)現(xiàn)六點(diǎn)布局

實(shí)現(xiàn)六點(diǎn)布局可以在四點(diǎn)布局的基礎(chǔ)上增加一行,示例代碼如下:

html

<body>
<div class="warp">
<div class="column">
<div class="pip"></div>
<div class="pip"></div>
</div>
<div class="column">
<div class="pip"></div>
<div class="pip"></div>
</div>
<div class="column">
<div class="pip"></div>
<div class="pip"></div>
</div>
</div>
</body>
復(fù)制代碼

css

.warp {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.column {
display: flex;
justify-content: space-around;
}
復(fù)制代碼

運(yùn)行效果如下:

圖片


責(zé)任編輯:武曉燕 來(lái)源: 前端YUE
相關(guān)推薦

2024-08-05 01:26:54

2021-12-02 08:19:06

MVCC面試數(shù)據(jù)庫(kù)

2025-03-12 00:52:00

Java樂(lè)觀鎖悲觀鎖

2020-05-22 08:11:48

線程池JVM面試

2022-11-15 17:45:46

數(shù)據(jù)庫(kù)MySQL

2023-05-10 13:58:13

服務(wù)限流系統(tǒng)

2019-12-02 10:51:11

Redis存儲(chǔ)系統(tǒng)

2024-04-08 10:35:59

JS代碼容量

2020-09-08 06:43:53

B+樹(shù)面試索引

2020-09-09 14:49:19

面試官數(shù)據(jù)結(jié)構(gòu)

2020-09-17 17:53:12

面試ArrayList數(shù)組

2020-07-02 07:52:11

RedisHash映射

2021-03-01 18:42:02

緩存LRU算法

2020-12-01 11:50:49

數(shù)據(jù)庫(kù)Redis面試

2020-02-25 16:56:02

面試官有話想說(shuō)

2024-05-09 10:33:14

JS計(jì)算容量

2021-02-28 07:52:24

蠕蟲(chóng)數(shù)據(jù)金絲雀

2023-03-30 07:34:10

Linux性能數(shù)據(jù)結(jié)構(gòu)

2025-02-27 00:08:24

2022-11-16 17:10:25

MySQL數(shù)據(jù)事務(wù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)