当前位置:   article > 正文

html/css基础之flex(弹性布局)_html的flex弹性布局 csdn

html的flex弹性布局 csdn

以下文章主要探讨 HTML5 中 CSS3 提供的用来实现未来响应式弹性伸缩布局方案。

一、flex布局的语法

块级元素 :display: flex ———— 将容器盒模型作为块级弹性伸缩盒显示

行内元素 :display: inline-flex ———— 将容器盒模型作为内联级弹性伸缩盒显示

设置flex布局后,flex item的float、clear和vertical-align 属性都失效

flex布局默认为横向

css

  1. <style>
  2. .flex-box{
  3. width: 1000px;
  4. height: 500px;
  5. margin: 0 auto;
  6. border: solid 1px red;
  7. display: flex;
  8. }
  9. .flex{
  10. width: 150px;
  11. height: 150px;
  12. background: blue;
  13. border: solid 1px rgb(255, 208, 0);
  14. }
  15. </style>

html

  1. <div class="flex-box">
  2. <div class="flex">第一个div</div>
  3. <div class="flex">第二个div</div>
  4. <div class="flex">第三个div</div>
  5. <div class="flex">第四个div</div>
  6. </div>

 加了"display:flex;"布局默认为横向

 

二、容器属性

flex的排列属性:

元素名称    

说明
flex-direction:column设置从上往下排列
flex-direction:column-reverse设置从下到上排列
flex-direction:row设置从左到右排列
flex-direction:row-reverse设置从右到左排列

1,加了"display:flex;flex-direction:column;"布局从上往下排列

2,加了"display:flex;flex-direction:column-reverse;"布局从上往下排列 

3,加了"display:flex;flex-direction:row;"布局从左到右排列

 4,加了"display:flex;flex-direction:row-reverse;"设置从右到左排列

flex换行属性:

没有设置子级flex为1时:flex-wrap

没有设置高度时会均分父级

元素名称说明
flex-wrap:nowrap默认值,都在一行或一列显示
flex-wrap:wrap伸缩项目无法容纳时,自动换行
flex-wrap:wrap-reverse伸缩项目无法容纳时,自动换行,方向和 wrap 相反

 1,当  flex-wrap: nowrap  时 ———— 默认值,都在一行或一列显示: 

  2,当  flex-wrap:wrap   时  ————伸缩项目无法容纳时,自动换行 :

  3,当  flex-wrap:wrap-reverse  时 ———— 伸缩项目无法容纳时,自动换行,方向和 wrap 相反 :

伸缩属性:

元素名称说明
justify-content:flex-start伸缩项目以起始点靠齐
justify-content:flex-end伸缩项目以结束点靠齐

justify-content:center

伸缩项目以中心点靠齐

justify-content:space-between

伸缩项目平均分布

justify-content:space-around

伸缩项目平均分布,但两端保留一半的空间

 1当  justify-content:flex-start  时  ————伸缩项目以起始点靠齐 :

2当  justify-content:flex-end  时  ———— 伸缩项目以结束点靠齐 :

3, 当  justify-content:center  时  ———— 伸缩项目以中心点靠齐 :

4,当  justify-content:space-between  时 ———— 伸缩项目平均分布 :

5,当  justify-content:space-around  时 ——— 伸缩项目平均分布,但两端保留一半的空间 :

  align-items属性:  ————  处理伸缩项目容器的额外空间

元素名称说明

align-itmes:flex-start

伸缩项目以顶部为基准,清理下部额外空间

align-itmes:flex-end

伸缩项目以底部为基准,清理上部额外空间

align-itmes:center

伸缩项目以中部为基准,平均清理上下部额外空间

align-itmes:baseline

伸缩项目以基线为基准,清理额外的空间

align-itmes:stretch

伸缩项目填充整个容器,默认

align-items属性的使用效果

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/325631
推荐阅读
相关标签
  

闽ICP备14008679号