当前位置:   article > 正文

html+css编写简单构造跳动爱心_html 跳动的心

html 跳动的心

目录

一.主要思路是

二.完整参考代码:

三.附上部分参考注释

四.最终效果


 

一.主要思路是

构造一个大盒子,里面放left、right、bottom三个小盒子,并将三个盒子设置好边框宽度、高度、弧度达到想要的形状(大致为上面两个圆下面一个矩形),为三个小盒子设置好背景色和阴影效果,最后为其设置动画效果

30866c6733e548d1aca2bc1bb7b0c6ca.png

二.完整参考代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>简易跳动爱心</title>
  6. <style>
  7. @keyframes myanimation {
  8. 0%{
  9. transform: scale(1) rotate(225deg);
  10. }
  11. 50%{
  12. transform: scale(1.2) rotate(225deg);
  13. }
  14. 100%{
  15. transform: scale(1) rotate(225deg);
  16. }
  17. }
  18. .all{
  19. width: 400px;
  20. height: 300px;
  21. top: 50px;
  22. position: relative;
  23. }
  24. .left{
  25. left: 30px;
  26. width: 200px;
  27. height: 200px;
  28. border-radius: 65%;
  29. }
  30. .right{
  31. right: 30px;
  32. width: 200px;
  33. height: 200px;
  34. border-radius: 65%;
  35. }
  36. .bottom{
  37. bottom: 30px;
  38. left: 100px;
  39. width: 200px;
  40. height: 200px;
  41. transform: rotate(45deg);
  42. border-radius: 8%;
  43. }
  44. .left,.right,.bottom{
  45. position: absolute;
  46. box-shadow:0 0 40px orangered;
  47. animation: myanimation 1.5s ease infinite normal;
  48. background: linear-gradient(-90deg, orangered 0%, orangered 100%);
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <div class="all">
  54. <div class="left"></div>
  55. <div class="right"></div>
  56. <div class="bottom"></div>
  57. </div>
  58. </body>
  59. </html>

三.附上部分参考注释

当然也可以尝试用用z-index属性来设置重叠效果是否满意

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>跳动爱心</title>
    <style>
        @keyframes myanimation {  

                /*这里要达到的效果主要是控制bottom盒子旋转缩放后位置通过角度计算达到重合*/
            0%{
                transform: scale(1) rotate(225deg);
            }
            50%{
                transform: scale(1.2) rotate(225deg);
            }
            100%{
                transform: scale(1) rotate(225deg);
            }
            /*变换效果:
            scale()表示对标签进行缩放可以写两个参数,第一个参数控制水平方向缩放,第二个控制垂直方向缩放
            rotate()表示对标签进行旋转,括号内写需要旋转度数*/
        }
        .all{
            width: 400px;
            height: 300px;
            top: 50px;                           /*图像上下左右位置参数可根据自身需求调整*/
            position: relative;                  /*.all作为父元素,需为其设置相对位置,“子绝父相”*/
        }
        .left{
            left: 30px;
            width: 200px;
            height: 200px;
            border-radius: 65%;        /*调整左上盒子的弧度*/
        }
        .right{
            right: 30px;
            width: 200px;
            height: 200px;
            border-radius: 65%;          /*调整右上盒子的弧度*/
        }
        .bottom{
            bottom: 30px;
            left: 100px;
            width: 200px;
            height: 200px;

            transform: rotate(45deg);    /*将下面的盒子旋转45度达到目标图形*/            
            border-radius: 8%;            /*调整下方盒子的弧度*/
        }
        .left,.right,.bottom{
            position: absolute;        /*三个子元素设置绝对位置属性*/
            box-shadow:0 0 40px orangered;    

             /*设置盒子阴影效果,四个参数含义:x轴偏移值,y轴偏移值,模糊度,颜色*/
            animation: myanimation 1.5s ease infinite normal;    

             /*调用animation属性为跳动激活属性,以常规动画方向无限循环跳动,每次跳动1.5秒*/
            background: linear-gradient(-90deg, orangered 0%, orangered 100%);  

             /*为三个子元素的背景设置渐变颜色,表示的意思是以负90度为渐变轴,从开始橘红色渐变到最后为橘红色,颜色建议选择相近色或相同色*/
        }
    </style>
</head>
<body>
    <div class="all">
        <div class="left"></div>
        <div class="right"></div>
        <div class="bottom"></div>
    </div>
</body>
</html>

四.最终效果

8004ebe4d9e8455f85c673a7550af096.png

 

 

 

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

闽ICP备14008679号