2-10 代码,请老师帮忙检查

来源:2-10 过渡效果实战课(2)

呜蜩的呀

2022-07-31 15:05:37

相关代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 508px;
            height: 107px;
            /* border: 1px solid #000; */
            margin: 40px auto;
        }

        .box ul {
            list-style: none;
        }

        .box ul li {
            float: left;
            width: 107px;
            height: 107px;
            /* background-color: aquamarine; */
            margin-right: 20px;
            position: relative;
        }

        /* 感觉如果使用background-image不是也一样可以插入对应的背景图片?为什么要选择伪元素更佳呢? */
        .box ul li::before {
            content: "";
            /* 因为伪元素生成的天生是行内元素,要设置宽高需要转成块级元素 */
            display: block;
            width: 107px;
            height: 107px;

            transform: rotate(0deg);
            transition: transform 1s linear 0s;
        }

        .box ul li:nth-child(1)::before {
            background-image: url(../作业素材/images/a_1.png);
        }

        .box ul li:nth-child(2)::before {
            background-image: url(../作业素材/images/a_2.png);
        }

        .box ul li:nth-child(3)::before {
            background-image: url(../作业素材/images/a_3.png);
        }

        .box ul li:nth-child(4)::before {
            background-image: url(../作业素材/images/a_4.png);
        }

        /* 压盖效果使用绝对定位 */
        .box ul li img {
            width: 60px;
            height: 60px;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -30px;
            margin-left: -30px;

            transform: scale(1);

            transition: transform 1s linear 0s;

        }

        .box ul li:hover::before {
            transform: rotate(360deg);
        }

        .box ul li:hover img {
            transform: scale(1.1);
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li>
                <!-- 为什么要用svg格式的呢?不能直接放png或者其他格式的图片吗? -->
                <img src="../作业素材/images/icon1.svg" alt="icon">
            </li>
            <li>
                <img src="../作业素材/images/icon2.svg" alt="icon">
            </li>
            <li>
                <img src="../作业素材/images/icon3.svg" alt="icon">
            </li>
            <li>
                <img src="../作业素材/images/icon4.svg" alt="icon">
            </li>
        </ul>
    </div>
</body>

</html>


写回答

1回答

好帮手慕慕子

2022-07-31

同学你好,代码实现是正确的,针对同学的问题解答如下:

因为讲师这里提供的图片是svg的,所以就使用了该格式,可以使用其他格式的,具体要看提供的是什么格式的图片。

祝学习愉快~

0

前端工程师

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

20327 学习 · 17877 问题

查看课程