老师好,请检查2-21代码

来源:2-21 自由编程

慕桂英1122475

2023-03-06 20:12:00

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>2-20</title>
    <style type="text/css">
      * {
        padding: 0;
        margin: 0;
      }
      .box {
        width: 100px;
        height: 100px;
        background-image: url(./images/xin.png);
        background-repeat: no-repeat;
      }
      .box1 {
        position: relative;
        margin: 50% auto;
       
      }
      .box2 {
        position: absolute;
        animation: bigger .5s ease 0s infinite;
      }

      @keyframes bigger{
        from{
            transform: scale(1);
           opacity: 1;
        }
        to{
            transform: scale(2);
            opacity: 0;
        }
      }
    </style>
  </head>
  <body>
    <div class="box1 box">
      <div class="box2 box"></div>
    </div>
  </body>
</html>

另外请问,为什么我将   .box {        width100px;        height100px;} 改成width200px height200px;以后,动画效果向左上偏移了,而没有维持原来中心扩散的效果?我本意是将图片放大的。



写回答

1回答

好帮手慕久久

2023-03-07

同学你好,代码是对的。问题解答如下:

设置成200px后,由于背景图尺寸小于200,背景图实际是位于左上角显示的:

https://img.mukewang.com/climg/640695c5097f546f05740356.jpg

所以最终看到的效果是斜的。

需要调整背景图的大小,让其与父元素一致:

https://img.mukewang.com/climg/640695f30968fdff07140205.jpg

祝学习愉快!

0

前端工程师

前端入门如同写字,如果你不知道从哪开始,那就选择前端(含Vue3.x,React17,TS)

20327 学习 · 17877 问题

查看课程