设置弹性布局的方向--语法 flex-direction:值
案例1代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;flex-direction:row;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例2代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;flex-direction:row-reverse;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例3代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;flex-direction:column;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例4代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;flex-direction:column-reverse;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
语法 flex-wrap:值
案例1代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap:nowrap;} .box img{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"> <img src="/uploads/240906/1-240Z62346094N.png" alt="" /> <img src="/uploads/240906/1-240Z62346094N.png" alt="" /> <img src="/uploads/240906/1-240Z62346094N.png" alt="" /> </div>
案例2代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap:wrap;} .box img{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"> <img src="/uploads/240906/1-240Z62346094N.png" alt="" /> <img src="/uploads/240906/1-240Z62346094N.png" alt="" /> <img src="/uploads/240906/1-240Z62346094N.png" alt="" /> </div>
案例3代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap:wrap-reverse;} .box img{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"> <img src="/uploads/240906/1-240Z62346094N.png" alt="" /> <img src="/uploads/240906/1-240Z62346094N.png" alt="" /> <img src="/uploads/240906/1-240Z62346094N.png" alt="" /> </div>
语法 justify-content:值
案例1代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;justify-content:flex-start;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例2代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;justify-content:flex-end;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例3代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;justify-content:center;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例4代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;justify-content:space-between;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例5代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;justify-content:space-around;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例6代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;justify-content:space-evenly;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
语法 align-content:值
案例1代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap: wrap;align-content:stretch;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例2代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap: wrap;align-content:flex-start;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例3代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap: wrap;align-content:flex-end;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例4代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap: wrap;align-content:center;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例5代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap: wrap;align-content:space-between;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例6代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap: wrap;align-content:space-around;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例7代码示例:
<style type="text/css"> .box{width: 100px;height: 300px;border: 1px solid #000;display: flex;flex-wrap: wrap;align-content:space-evenly;} .box div{width: 80px;height: 80px;border: 1px solid #1e90ff;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
语法 align-items:值
案例1代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;align-items:flex-start;} .box div{width: 80px;border: 1px solid #1e90ff;} .box div:first-child{height: 120px;background: #f00;} .box div:nth-child(2){height: 80px;background: #0f0;} .box div:last-child{height: 100px;background: #00f;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例2代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;align-items:flex-end;} .box div{width: 80px;border: 1px solid #1e90ff;} .box div:first-child{height: 120px;background: #f00;} .box div:nth-child(2){height: 80px;background: #0f0;} .box div:last-child{height: 100px;background: #00f;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例3代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;align-items:center;} .box div{width: 80px;border: 1px solid #1e90ff;} .box div:first-child{height: 120px;background: #f00;} .box div:nth-child(2){height: 80px;background: #0f0;} .box div:last-child{height: 100px;background: #00f;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例4代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;align-items:baseline;} .box div{width: 80px;border: 1px solid #1e90ff;} .box div:first-child{height: 120px;background: #f00;} .box div:nth-child(2){height: 80px;background: #0f0;} .box div:last-child{height: 100px;background: #00f;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
案例5代码示例:
<style type="text/css"> .box{width: 300px;height: 300px;border: 1px solid #000;display: flex;align-items:stretch;} .box div{width: 80px;border: 1px solid #1e90ff;} .box div:first-child{height: 120px;background: #f00;} .box div:nth-child(2){height: 80px;background: #0f0;} .box div:last-child{height: 100px;background: #00f;} </style> <div class="box"><div>盒子1</div><div>盒子2</div><div>盒子3</div></div>
总结:弹性盒子布局兼容写法
display: -moz-box; /*firefox*/
display: -ms-flexbox; /*IE10*/
display: -webkit-box; /*Safari*/
display: -webkit-flex; /*Chrome*/
display: box;
display: flexbox;
display: flex;
以上内容,在整理时难免有疏漏错误之处,如有发现,可以通过顶部的“联系站长”提出反馈,感谢您的支持!