flex布局练习题,面试必备,持续更新建议收藏~

先言:

 现在网页布局大多都是flex布局,像浮动这些用得比较少,在面试中flex也是被经常问到的。而有些同学学完flex后,又不懂怎么练习巩固,所以,所以,所以,我汇聚了一些常见的flex的练习题案例,写完再次加强掌握flex~

在这里插入图片描述

第一题:

效果如下,先看效果自己写或者思考,最后再看代码:

在这里插入图片描述
html:

<div class="container">
   <div class="item"> </div>
</div>

css:

.container{
  width: 300px;
  height: 300px;
  background-color: skyblue;
  display: flex;
  justify-content: center;
  align-items: center;
}
.item{
  width: 100px;
  height: 100px;
  background-color: blue;
}

第二题:

效果如下:
在这里插入图片描述
html:

<div class="container">
   <div class="item"> </div>
   <div class="item"> </div>
   <div class="item"> </div>
   <div class="item"> </div>
   <div class="item"> </div>
   <div class="item"> </div>
</div>

css:

.container{
  width: 300px;
  height: 300px;
  background-color: skyblue;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  align-content: space-around;
}
.item{
  width: 80px;
  height: 80px;
  background-color: blue;
}

第三题:

先看效果:
在这里插入图片描述html:

<div class="container">
   <div class="item"> </div>
   <div class="item"> </div>
</div>

css:

.container{
  width: 300px;
  height: 300px;
  background-color: skyblue;
  display: flex;
  justify-content: space-between;
}
.item{
  width: 80px;
  height: 80px;
  background-color: blue;
}
.container div:nth-of-type(2){
    align-self: flex-end;
}

第四题:

先看效果:
在这里插入图片描述
html:

<div class="container">
   <div class="item"> </div>
   <div class="item"> </div>
   <div class="item"> </div>
</div>

css:

.container{
  width: 300px;
  height: 300px;
  background-color: skyblue;
  display: flex;
  justify-content: space-between;
}
.item{
  width: 80px;
  height: 80px;
  background-color: blue;
}
.container div:nth-of-type(2){
    align-self: center;
}
.container div:nth-of-type(3){
  align-self: flex-end;
}

第五题:

先看效果:
在这里插入图片描述
html:

<div class="container">
  <div class="first">
    <div class="item"> </div>
    <div class="item"> </div>
  </div>
   <div class="second">
    <div class="item"> </div>
    <div class="item"> </div>
  </div>
</div>

css:

.container{
  width: 300px;
  height: 300px;
  background-color: skyblue;
  display: flex;
  justify-content: space-between;

}
.item{
  width: 80px;
  height: 80px;
  background-color: blue;
  border: 1px solid green;
}
.first,.second{
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

第六题:

先看效果:
在这里插入图片描述
html:

<div class="container">
  <div class="first">
    <div class="item"> </div>
    <div class="item"> </div>
  </div>
   <div class="second">
    <div class="item"> </div>
  </div>
    <div class="three">
    <div class="item"> </div>
    <div class="item"> </div>
  </div>
</div>

css:

.container{
  width: 300px;
  height: 300px;
  background-color: skyblue;
  display: flex;
  justify-content: space-between;

}
.item{
  width: 80px;
  height: 80px;
  background-color: blue;
  border: 1px solid green;
}
.first,.three{
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.second{
  align-self: center;
}

第七题:

先看效果:
在这里插入图片描述

html:

<div class="container">
  <div class="first">
    <div class="item"> </div>
    <div class="item"> </div>
    <div class="item"> </div>
  </div>
   <div class="second">
    <div class="item"> </div>
    <div class="item"> </div>
    <div class="item"> </div>
  </div>
</div>

css:

.container{
  width: 300px;
  height: 300px;
  background-color: skyblue;
  display: flex;
  justify-content: space-between;

}
.item{
  width: 80px;
  height: 80px;
  background-color: blue;
  border: 1px solid green;
}
.first,.second,.three{
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

第八题:

先看效果,两边盒子宽不变,中间盒子动态适应宽度大小:

在这里插入图片描述
html:

<div class="container">
  <div class="first">1</div>
   <div class="second">2</div>
   <div class="third">3</div>
</div>

css:

.container{
  width:100%;
  height: 100px;
  background-color: skyblue;
  display: flex;
  justify-content: space-around;
}
.first{
  width:100px;
  background-color: red;
}
.second{
  background-color: orange;
  flex-grow: 1;
}
.third{
  width:100px;
  background-color: pink;
}

第九题:

先看效果,左右上下都能动态调整大小:

在这里插入图片描述
html:

<div class="container">
  <div class="head">1</div>
   <div class="body">
      <div class="body-left">2.1</div>
      <div class="body-center">2.2</div>
   </div>
   <div class="footer">3</div>
</div>

css:

.container{
  height: 100vh;
  background-color: skyblue;
  display: flex;
  flex-direction: column;
}
.head{
   background-color: blue;
   flex-grow: 2;
}
.body{
  display: flex;
  flex-grow: 5;
}
.body-left{
   background-color: green;
  flex-grow: 1;
}
.body-center{
   background-color: pink;
  flex-grow: 5;
}
.footer{
  flex-grow: 1;
   background-color: orange;
}

第十题:

先看效果,也是动态改变大小的:

在这里插入图片描述
html:

<div class="container">
  <div class="first">
     <div class="item" style="background: red;">A</div>
     <div class="item" style="background: yellow;">B</div>
     <div class="item" style="background: blue;">C</div>
  </div>
   <div class="second">
      <div class="box">
           <div class="item" style="background: green;">D</div>
           <div class="item" style="background: pink;">E</div>
      </div>
      <div class="bigitem" style="background: orange;">F</div>
  </div>   
</div>

css:

.container{
  height: 100vw;
  width: 100vw;
  background-color: skyblue;
  display: flex;
  flex-direction: column;
  
 }
.item{
  flex: 1;
}

.first{
  display: flex;
  flex: 1;
}
.second{
   display: flex;
   flex: 2;
}
.box{
    display: flex;
    flex-direction: column;
    flex: 1;
}
.bigitem{
  flex: 2;
}

总结:

建议收藏,这篇文章持续更新,会一直添加flex布局案例练习题~

~关注我看更多简单创意特效:
文字烟雾效果 html+css+js
环绕倒影加载特效 html+css
气泡浮动背景特效 html+css
简约时钟特效 html+css+js
赛博朋克风格按钮 html+css
仿网易云官网轮播图 html+css+js
水波加载动画 html+css
导航栏滚动渐变效果 html+css+js
书本翻页 html+css
3D立体相册 html+css
霓虹灯绘画板效果 html+css+js
记一些css属性总结(一)
Sass总结笔记
…等等
进我主页看更多~

  • 46
    点赞
  • 107
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 53
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 53
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北极光之夜。

谢谢~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值