swift瀑布流实现_CSS 实现瀑布流布局(display: flex)
生活随笔
收集整理的這篇文章主要介紹了
swift瀑布流实现_CSS 实现瀑布流布局(display: flex)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
作者 | chokcoco
本例使用 CSS flex 實現瀑布流布局。
關鍵點,橫向 flex 布局嵌套多列縱向 flex 布局,使用了 vw 進行自適應縮放。
代碼如下:
HTML:
// pug 模板引擎div.g-container
-for(var i = 0; i<4; i++)
div.g-queue
-for(var j = 0; j<8; j++)
div.g-item
SCSS:
$lineCount: 4;$count: 8;
@function randomNum($max, $min: 0, $u: 1) {
@return ($min + random($max)) * $u;
}
@function randomColor() {
@return rgb(randomNum(255), randomNum(255), randomNum(255));
}
.g-container {
display: flex;
flex-direction: row;
justify-content: space-between;
overflow: hidden;
}
.g-queue {
display: flex;
flex-direction: column;
flex-basis: 24%;
}
.g-item {
position: relative;
width: 100%;
margin: 2.5% 0;
}
@for $i from 1 to $lineCount+1 {
.g-queue:nth-child(#{$i}) {
@for $j from 1 to $count+1 {
.g-item:nth-child(#{$j}) {
height: #{randomNum(300, 50)}px;
background: randomColor();
&::after {
content: "#{$j}";
position: absolute;
color: #fff;
font-size: 24px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
}
}
}
效果如下(點擊?Pug/SCSS?可以對代碼進行編輯):
總結
以上是生活随笔為你收集整理的swift瀑布流实现_CSS 实现瀑布流布局(display: flex)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python的tkinter编写计算器_
- 下一篇: python中的取余运算符是_pytho