美文网首页
flex布局实现骰子六个面的写法

flex布局实现骰子六个面的写法

作者: 候鸟与暖风 | 来源:发表于2019-12-02 09:57 被阅读0次

1.flex实现骰子六个面之<布局一>

image.png
 <ul class="view-box1 container">
    <li class="one">1</li>
  </ul>
.view-box1 {
  background-color: #f5f5f5;
  width: 200px;
  height: 200px;
  margin-top:20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.one {
  background-color: aqua;
  width: 40px;
  height: 40px;
}

2.flex实现骰子六个面之<布局二>

image.png
  <ul class="view-box1 container">
    <li class="one">1</li>
    <li class="two">2</li>
  </ul>
.view-box1 {
  background-color: #f5f5f5;
  width: 200px;
  height: 200px;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  justify-content:space-evenly;
  align-items: center;
}

.one {
  background-color: aqua;
  width: 40px;
  height: 40px;
}

.two {
  background-color: pink;
  width: 40px;
  height: 40px;
}

3.flex实现骰子六个面之<布局三>

image.png
 <ul class="view-box1 container">
    <li class="one">1</li>
    <li class="two">2</li>
    <li class="three">3</li>
  </ul>
.view-box1 {
  background-color: #f5f5f5;
  width: 200px;
  height: 200px;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  justify-content:space-between;
}

.one {
  background-color: aqua;
  width: 40px;
  height: 40px;
}

.two {
  background-color: pink;
  width: 40px;
  height: 40px;
  align-self: center
}
.three {
  background-color: #ff3040;
  width: 40px;
  height: 40px;
  align-self: flex-end;
}

4.flex实现骰子六个面之<布局四>

image.png
 <div class="view-layout">
    <ul class="view-box1">
      <li class="one">1</li>
      <li class="two">2</li>
    </ul>
    <ul class="view-box2">
      <li class="three">1</li>
      <li class="four">2</li>
    </ul>
  </div>
.view-layout {
  display: flex;
  flex-direction: column;  //主轴为垂直方向
  width: 200px;
  height: 200px;
}

.view-box1 {
  background-color: #f5f5f5;
  flex-grow: 1;  //按照比例均分父元素的剩余空间
  display: flex;
  align-items: center;//项目在交叉轴方向居中
  justify-content: space-evenly;  //项目在主轴方向间距均等分布
}

.view-box2 {
  background-color: #ccc;
  flex-grow: 1;    //
  display: flex;
  align-items: center;    
  justify-content: space-evenly;  
}

.one {
  background-color: aqua;
  width: 40px;
  height: 40px;
}
.two {
  background-color: pink;
  width: 40px;
  height: 40px;
}
.three {
  background-color: #ff3040;
  width: 40px;
  height: 40px;
}

.four {
  background-color: aquamarine;
  width: 40px;
  height: 40px;
}

5.flex实现骰子六个面之<布局五>

image.png
 <div class="view-container">
    <ul class="view-box1">
      <li class="one">1</li>
      <li class="two">2</li>
    </ul>
    <ul class="view-box2">
      <li class="three">3</li>
    </ul>
    <ul class="view-box3">
      <li class="four">4</li>
      <li class="five">5</li>
    </ul>
  </div>
.view-box1,
.view-box2,
.view-box3 {
  background-color: #f5f5f5;
  width: 240px;
  height: 80px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.view-box2 {
  background-color: antiquewhite;
}
.view-box3 {
  background-color: #666;
}

.one {
  background-color: aqua;
  width: 50px;
  height: 50px;
}

.two {
  background-color: pink;
  width: 50px;
  height: 50px;
}
.three {
  background-color: #ff3040;
  width: 50px;
  height: 50px;
}

.four {
  background-color: aquamarine;
  width: 50px;
  height: 50px;
}

.five {
  background-color: orange;
  width: 50px;
  height: 50px;
}

6.flex实现骰子六个面之<布局六>

image.png
 <div class="view-container">
    <ul class="view-box1">
      <li class="one">1</li>
      <li class="two">2</li>
    </ul>
    <ul class="view-box2">
      <li class="three">3</li>
      <li class="four">4</li>
    </ul>
    <ul class="view-box3">
      <li class="five">5</li>
      <li class="six">6</li>
    </ul>
  </div>
.view-box1,
.view-box2,
.view-box3 {
  background-color: #f5f5f5;
  width: 240px;
  height: 80px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.view-box2{
  background-color: antiquewhite
}
.view-box3{
  background-color: #666
}

.one {
  background-color: aqua;
  width: 50px;
  height: 50px;
}

.two {
  background-color: pink;
  width: 50px;
  height: 50px;
}
.three {
  background-color: #ff3040;
  width: 50px;
  height: 50px;
}

.four {
  background-color: aquamarine;
  width: 50px;
  height: 50px;
}

.five {
  background-color: orange;
  width: 50px;
  height: 50px;
}

.six {
  background-color: black;
  width: 50px;
  height: 50px;
}

以上是我自己写的小demo,使用flex布局实现骰子六个面写法, 这年头不会flex布局,真的不行,之前我也是觉得用定位,百分比布局也够了,就不太想学flex布局,后来面试的时候,别人正好问到了flex布局,然后我就被完虐了,受到打击之后,就自学了flex布局,学习了之后,才发现flex布局真的很好用,真的后悔没早点学习,建议各位前端朋友们也都学习下flex布局哦

相关文章

  • flex布局实现骰子六个面的写法

    1.flex实现骰子六个面之<布局一> 2.flex实现骰子六个面之<布局二> 3.flex实现骰子六个面之<布局...

  • Flex 布局教程:实例篇

    今天介绍常见布局的Flex写法。你会看到,不管是什么布局,Flex往往都可以几行命令搞定。 一、骰子的布局骰子的一...

  • flex布局实现骰子

    学习flex布局后的实例布局--骰子具体实现原理可参考阮一峰的Flex 布局教程:实例篇和博客flex布局实现色子...

  • 骰子布局Flex写法

    骰子布局1-6 html模板:把骰子面板当成一个容器,骰子中的每个点相当于每个项。 ①一个点 html: css:...

  • 2019年9月前端面试汇总

    1. flex实现骰子5点布局(答案不唯一) 简单的思路:1.flex布局横向排列,flex-flow:wrap ...

  • Flex实例

    一、骰子布局 单项目分别对骰子的1~9个点进行通过代码来实现首先对单一点就行布局。首先以为flex布局具有自身的默...

  • flex布局实现骰子样式

    flex原理网上很多博客都讲解的很详细,这篇博客属于实战,利用flex来实现一些有趣好玩的样式——骰子样式 如何利...

  • CSS-Flex 布局教程:实例篇

    参考文章:Flex 布局教程:实例篇 一、骰子的布局 骰子的一面,最多可以放置9个点。 下面,就来看看Flex如何...

  • Flex网页布局二CSS弹性伸缩盒子写法教程

    上一篇文章:Flex 布局写法教程 介绍了Flex布局的语法,今天介绍常见布局的Flex写法。 你会看到,不管是什...

  • css笔记-6/flex之前的布局

    flex布局 flex之前的布局 flex之后 基本概念 flex container的六个属性 flex ite...

网友评论

      本文标题:flex布局实现骰子六个面的写法

      本文链接:https://www.haomeiwen.com/subject/trjxgctx.html