• 50个html+css+js项目小练习(一:3D小黄人图片旋转样式)


    1.3D-boxes-background

    在这里插入图片描述

    实现步骤:
    • body设置为flex布局,超出部分隐藏(浏览器的下拉被隐藏)
    • 创建基本样式boxes大盒子
    • 利用js创建box小盒子
    • 使用flex把box小盒子之间的距离拉开
    • 把小盒子的3D阴影做出了,
      • 下方在小盒子下方的横向线,向X轴倾斜45°
      • 右方在小盒子右方的竖向线,向Y轴倾斜45°
    • 再把小黄人平分给每一个小盒子

      /* 要满足boxes且满足big的情况 */
      .boxes.big {
            width: 600px;
            height: 600px;
      }
      .boxes.big .box {
            transform: rotateZ(360deg);
      }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
    知识点:
    flex知识点:
    • 父为flex,子的float、clear、vertical-align失效。
    • flex-direction:设主轴的方向
    • justify-content:设主轴上的子元素排列方式
    • flex-wrap:设子元素是否换行
    • 行align-content:设侧轴上的子元素的排列方式
    • 行align-items:设置侧轴上的子元素的排列方式
    • flex-flow:复合属性,flex-direction + flex-wrap
    fix知识点:
    • 相对于浏览器窗口进行定位。
    • 使用left,right,top,bottom等进行定位。
    多类选择器:
    • 把两个类选择器连接在一起,可以选择同时包含这些类名的元素(类名的顺序不限)
    • 如果一个多类选择器包含类名列表中没有的一个类名,匹配就会失败。

    一个特定的元素同时标记为重要 ( important ) 和警告 ( warning )

    "important warning">

    • 1
    • class 为 important 的所有元素都是粗体,class 为 warning 的所有元素为斜体,
    • class 中同时包含important 和warning的所有元素还有一个银色的背景 。
    .important {font-weight:bold;}
    .warning {font-style:italic;}
    .important.warning {background:silver;}
    
    • 1
    • 2
    • 3

    https://www.w3school.com.cn/css/css_selector_class.asp

    其他知识点:
    • outline:none; 无效,使绘制于元素周围的一条线无效。button点击时,外圈会出现一条线,它的作用就是让这一圈线不显示
    • skewY向Y轴倾斜,标签内的文字等都会一起倾斜
    • toggle ( ) :每次点击时,切换要调用的函数。

    完整代码:

     * {
          box-sizing: border-box;
        }
        body {
          background-color: rgb(220, 250, 241);
          font-family: 'Courier New', Courier, monospace;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          height: 100vh;
          overflow: hidden;
        }
        .magic {
          background-color: rgb(104, 72, 184);
          color: aliceblue;
          font-family: 'Courier New', Courier, monospace;
          border: 0;
          border-radius: 3px;
          font-size: 26px;
          padding: 12px 20px;
          /* 设置为手指鼠标模式 */
          cursor: pointer;
          /* 设置固定定位 */
          position: fixed;
          top: 200px;
          letter-spacing: 1px;
          box-shadow: 0 3px rgba(82, 73, 189, 0.5);
          /* 最高层,防止点击不出来 */
          z-index: 100;
        }
        .magic:focus {
          outline: none;
        }
        .magic:active {
          box-shadow: none;
          transform: translateY(2px);
        }
        .boxes {
          display: flex;
          flex-wrap: wrap;
          justify-content: space-around;
          width: 500px;
          height: 500px;
          /* position: relative; */
          transition: .4s ease;
        }
        /* 要满足boxes且满足big的情况 */
        .boxes.big {
          width: 600px;
          height: 600px;
        }
        .boxes.big .box {
          transform: rotateZ(360deg);
        }
        .box {
          background-image: url('https://media.giphy.com/media/EZqwsBSPlvSda/giphy.gif');
          background-repeat: no-repeat;
          background-size: 500px 500px;
          width: 125px;
          height: 125px;
          transition: .4s ease;
          position: relative;
        }
        .box::after {
          content: '';
          background-color: rgb(134, 125, 218);
          position: absolute;
          top: 8px;
          right: -15px;
          height: 100%;
          width: 15px;
          transform: skewY(45deg);
        }
        .box::before {
          content: '';
          background-color: rgb(134, 125, 218);
          position: absolute;
          bottom: -15px;
          left: 8px;
          height: 15px;
          width: 100%;
          transform: skewX(45deg);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    <button id="btn" class="magic">magicbutton>
    <div id="boxes" class="boxes big">div>
    <script>
        const boxesContainer = document.getElementById('boxes')
        const btn = document.getElementById('btn')
        //点击切换:big是否可见
        btn.addEventListener('click', () => boxesContainer.classList.toggle('big'))
        // 创建小盒子
        function createBoxes () {
          for (let i = 0; i < 4; i++) {
            for (let j = 0; j < 4; j++) {
              const box = document.createElement('div')
              box.classList.add('box')
              box.style.backgroundPosition = `${-j * 125}px ${-i * 125}px`
              boxesContainer.appendChild(box)
            }
          }
        }
        createBoxes()
    script>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    点击magic

  • 相关阅读:
    etcd的mvcc源码剖析
    @Async注解详解+实例
    Cloudpods容器化经验分享
    C/C++源程序到可执行程序exe的全过程(及汇编和反汇编的区别)
    Servlet总结
    【知识总结】金九银十offer拿到手软的前端面试题——Web篇
    计算机的分类有两种
    嵌入式分享合集27
    设计模式 人类父母和猫孩子的关系理解观察者模式(发布订阅模式)
    Java8实战-总结33
  • 原文地址:https://blog.csdn.net/m0_54088431/article/details/127832714