Blogger Information
Blog 36
fans 1
comment 0
visits 29632
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
hTML之FLEX布局属性
Jason
Original
2341 people have browsed it

HTML之flex布局

flex布局是什么

flex布局,中文意思为弹性布局,用来为盒模型提供最大的支持,如果靠简单的float,position,很难将页面做的好看。flex灵活性非常的好,任何一个容器都可以定义为flex布局。下面通过案例来演示flex的属性

1.flex-direction

代码(这里只将属性部分写出):

  1. flex-direction: row;
  2. /* 从右至左 */
  3. flex-direction: row-reverse;
  4. /* 从上至下 */
  5. flex-direction: column;
  6. /* 从下至上 */
  7. flex-direction: column-reverse;

效果图:
direction方向

2.flex-wrap

代码

  1. flex-wrap: nowrap;
  2. flex-wrap: wrap;
  3. flex-wrap: wrap-reverse;

`
效果图:
多行容器

3.flex-fow

代码

  1. flex-direction: row;
  2. flex-wrap: wrap;
  3. flex-flow: row nowrap;
  4. flex-flow: column wrap;

效果图:
简写

4.justify-content

代码:

  1. justify-content: center;
  2. justify-content:space-evenly;
  3. justify-content:space-around;
  4. justify-content: space-between;

效果图:
横轴对齐方式

5.align-items

代码:

  1. .container {
  2. align-items: flex-end;
  3. /* align-items: flex-start; */
  4. align-items: center;
  5. }

效果图:
交叉轴对齐方式

6.flex-content

代码:

  1. .container {
  2. align-content: flex-start;
  3. align-content: flex-end;
  4. align-content: center;
  5. }

效果图:
交叉轴对齐方式

7.flex-order

代码:

  1. .item:nth-of-type(2){
  2. order:1;
  3. background-color: chocolate;
  4. }
  5. .item:nth-last-of-type(){
  6. order:3;
  7. background-color: coral;
  8. }

效果图:
flex排序

8.align-self

代码

  1. .item:first-of-type {
  2. width:50px;
  3. height:50px;
  4. background-color: lightslategray;
  5. align-self:center;
  6. }

效果图:
项目独立对齐方式

9.flex-grow

代码

  1. .item:first-of-type {
  2. flex-grow: 1;
  3. }
  4. .item:nth-of-type(2) {
  5. flex-grow: 2;
  6. }
  7. .item:nth-of-type(3) {
  8. flex-grow: 3
  9. }

效果图:
项目放大

10.flex-shrink

代码

  1. .item:first-of-type {
  2. background-color: lawngreen;
  3. flex-shrink: 1;
  4. }
  5. .item:nth-of-type(2) {
  6. background-color:lightcoral;
  7. flex-shrink: 2;
  8. }
  9. .item:last-of-type {
  10. background-color:blue;
  11. flex-shrink: 3;
  12. }

效果图
项目缩小

11.flex-basis

代码:

  1. .item {
  2. flex-basis: auto;
  3. flex-basis: 70px;
  4. flex-basis: 20%;
  5. max-width: 30px;
  6. /* 权重关系:min-width/max-width>flex-basis>width */
  7. /* width < flex-basis < min/max-width; */
  8. }

效果图:
设置项目宽度

12.flex简写

代码:

  1. .item:first-of-type {
  2. background-color: lightslategrey;
  3. flex: 0 1 auto;
  4. }
  5. .item:nth-of-type(2) {
  6. background-color: lime;
  7. flex: 0 1 200px;
  8. }
  9. .item:last-of-type {
  10. background-color: maroon;
  11. flex:auto;
  12. flex: none;
  13. }

效果图:
flex简写

总结

通过上课的十二个案例讲解,已经大概明白了flex属性的用法,整个属性大概了解了50%,剩下的还需要温故而知新,台上一分钟,台下十年攻,上课看似很轻松,下课却需要仔细揣摩,每个属性的用法,以及组合产生的作用,对于flex属性的用法,还需要加强,做完案例后,脑袋里还是非常的模糊,没有确切的认知,这也说明了老师说上课说能明白50%就不错了,还需要通过案例来巩固基本知识,做项目来加强认知与理解。

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:学习本身就是一个痛苦的过程 , 非常正确,坚持
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!