今天所学心得、笔记
1、将flex容器与项目的常用属性全部进行实例演示;
示例代码,CSS部分
<style>
.container {
min-height: 10em;
border: solid 1px;
}
.item {
font-size: 2em;
font-weight: bold;
text-align: center;
width: 3em;
background-color: violet;
border: solid 1px;
}
.container {
display: flex;
/*水平排列,反顺序*/
flex-direction: row-reverse;
/*垂直排列*/
flex-direction: column;
/*垂直排列,反顺序*/
flex-direction: column-reverse;
/*水平排列,允许换行*/
flex-flow: wrap;
/*水平排列,元素紧贴左边*/
justify-content: flex-start;
/*水平排列,元素紧贴右边*/
justify-content: flex-end;
/*水平排列,剩余空间在元素中间平分,最左右两边无空间*/
justify-content: space-between;
/*水平排列,剩余空间在元素两边平分,最左右两边有空间*/
justify-content: space-around;
/*水平排列,剩余空间以元素数量平分,最左右两边有空间*/
justify-content: space-evenly;
/*垂直排列,元素置顶*/
align-items: flex-start;
/*垂直排列,元素置底*/
align-items: flex-end;
/*垂直排列,元素居中*/
align-items: center;
/*垂直排列,元素拉伸*/
align-items: stretch;
}
.container .item:nth-of-type(1) {
/*垂直排列,该元素置顶*/
align-self: flex-start;
/*1号元素,布置在最后,第4*/
order: 10;
/*1号元素最总容器的 10%*/
flex: 1;
}
.container .item:nth-of-type(2) {
/*垂直排列,该元素居中*/
align-self: center;
/*2号元素,倒数第2,第4*/
order: 8;
flex: 2;
}
.container .item:nth-of-type(3) {
/*垂直排列,该元素置底部*/
align-self: flex-end;
/*3号元素,布置在第2*/
order: 6;
/*3号元素最总容器的 30%*/
flex: 3;
}
.container .item:nth-of-type(4) {
/*垂直排列,该元素拉伸*/
align-self: stretch;
/*4号元素,布置在第1*/
order: 3;
/*4号元素最总容器的 40%*/
flex: 4;
}
</style>
示例代码,HTML部分
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<!-- <div class="item">5</div>-->
<!-- <div class="item">6</div>-->
<!-- <div class="item">7</div>-->
<!-- <div class="item">8</div>-->
<!-- <div class="item">9</div>-->
<!-- <div class="item">10</div>-->
</div>
示例代码截图部
![](https://img.php.cn/upload/image/169/535/744/1610818708303251.png)
![](https://img.php.cn/upload/image/617/597/826/1610818719448206.png)
![](https://img.php.cn/upload/image/703/859/722/1610818731324290.png)
![](https://img.php.cn/upload/image/328/899/936/1610818741744224.png)
![](https://img.php.cn/upload/image/330/104/384/1610818748189384.png)
![](https://img.php.cn/upload/image/279/823/135/1610818760630573.png)
![](https://img.php.cn/upload/image/685/175/918/1610818769170625.png)
![](https://img.php.cn/upload/image/813/657/597/1610818777293478.png)
![](https://img.php.cn/upload/image/800/192/816/1610818792312758.png)
![](https://img.php.cn/upload/image/984/102/921/1610818800834139.png)
![](https://img.php.cn/upload/image/230/103/907/1610818807894914.png)
![](https://img.php.cn/upload/image/711/378/453/1610818814508401.png)
![](https://img.php.cn/upload/image/367/165/780/1610818822616682.png)
![](https://img.php.cn/upload/image/746/273/793/1610818829322731.png)
![](https://img.php.cn/upload/image/152/695/530/1610818838782469.png)
![](https://img.php.cn/upload/image/640/124/621/1610818845833791.png)
![](https://img.php.cn/upload/image/981/160/482/1610818852752867.png)