flex布局案例-基础
可用F12开发者工具查看元素及样式,可打开codepen在线编辑代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| ``` html <html> <div class="box"> <span>1</span> <span>2</span> <span>3</span> <span>4</span> <span>5</span> <span>6</span> <span>7</span> </div> </html> <style>
.box{ width: 350px; height: 300px; background: #eee; display: flex; flex-direction: row; flex-wrap: wrap; flex-flow: row wrap; justify-content: space-around;
align-items: center
align-content:flex-start
}
.box span{ display:block;width: 50px;height: 50px;background: mediumspringgreen;margin: 10px;text-align: center;line-height: 50px;
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
flex:0 1 auto; } .box span:nth-child(2){ order: -1; background: red; } .box span:nth-child(7){
align-self: flex-end; background: blue; } </style>
|
> 参考:<http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html>
---
> 来源:本文导入自 [xugaoyi/vuepress-theme-vdoing](https://github.com/xugaoyi/vuepress-theme-vdoing/blob/d77b420/docs/02.%E9%A1%B5%E9%9D%A2/20.CSS/02.flex%E5%B8%83%E5%B1%80%E6%A1%88%E4%BE%8B-%E5%9F%BA%E7%A1%80.md) 的 `docs/02.页面/20.CSS/02.flex布局案例-基础.md`。
> 原作者:xugaoyi。许可证:[MIT](https://github.com/xugaoyi/vuepress-theme-vdoing/blob/d77b420/LICENSE)。