偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

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

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

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

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

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

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

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

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

多說無益,我們直接來寫代碼

實現(xiàn)一點布局

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

html

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

css

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

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

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

圖片

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

實現(xiàn)二點布局

現(xiàn)在我們實現(xiàn)色子的二點布局,實現(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ù)制代碼

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

圖片

實現(xiàn)三點布局

三點布局與二點布局類似,只需要再添加一行即可,實現(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ù)制代碼

運行效果如下:

圖片

實現(xiàn)四點布局

四點布局可以說是二點布局的變種,實現(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ù)制代碼

運行效果如下:

圖片

實現(xiàn)五點布局

實現(xià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ù)制代碼

運行效果如下:

圖片

實現(xiàn)六點布局

實現(xià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ù)制代碼

運行效果如下:

圖片


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

2024-08-05 01:26:54

2025-03-12 00:52:00

Java樂觀鎖悲觀鎖

2021-12-02 08:19:06

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

2020-05-22 08:11:48

線程池JVM面試

2022-11-15 17:45:46

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

2023-05-10 13:58:13

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

2019-12-02 10:51:11

Redis存儲系統(tǒng)

2024-04-08 10:35:59

JS代碼容量

2020-09-08 06:43:53

B+樹面試索引

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ù)庫Redis面試

2020-02-25 16:56:02

面試官有話想說

2024-05-09 10:33:14

JS計算容量

2023-03-30 07:34:10

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

2021-02-28 07:52:24

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

2025-02-27 00:08:24

2009-09-28 10:58:45

招聘
點贊
收藏

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