麻烦老师检查是否有误和修改的地方

来源:4-15 项目作业

dww1

2021-11-20 17:33:48

<style>
        .box{
            width: 100%;
            background-color: gray;
            overflow: hidden;
        }
        .box .btn{
            float: left;
            padding: 40px;
        }
        .box .box1 .car{
            float: right;
        }
        .box .box1{
            position: relative;
        }
        .box .box1 span{
            position: absolute;
            top: 10px;
            right: 3px;
            display: block;
            width: 40px;
            height: 40px;
            background-color: red;
            border-radius: 50%;
            text-align: center;
            line-height: 40px;
            color: #fff;
        }
    </style>
div class="box">
        <img src="imgs/btn.png" class="btn" alt="">
        <div class="box1">
            <img src="imgs/cart.png" class="car" alt="">
            <span>3</span>
        </div>
       
    </div>


写回答

1回答

好帮手慕久久

2021-11-20

同学你好,代码没有错误,但是整体效果有点丑,建议做如下调整:

1、建议给div.box设置固定宽度,并调整背景色:

https://img.mukewang.com/climg/6198c1f909ac221506340276.jpg

2、div.box共有两个子元素(儿子),分别是img和div.box1,二者在一行显示,因此建议将浮动设置在二者身上,这样更好些:

https://img.mukewang.com/climg/6198c29a094a80ee06410417.jpg

3、左侧按钮位置有点靠上:

https://img.mukewang.com/climg/6198c2ba094a42b204730241.jpg

建议往下调整一下:

https://img.mukewang.com/climg/6198c301092d486005310162.jpg

4、右侧图片太大了,整体不协调,建议调小:

https://img.mukewang.com/climg/6198c38609a71d7408600189.jpg

https://img.mukewang.com/climg/6198c3b9095a413606570425.jpg

代码如下:

 .box {
            /* width: 100%; */
            width:750px;
            /* background-color: gray; */
            background-color: #f1f1f1;
            overflow: hidden;
            /* 让其整体居中 更好看 */
            margin: 0 auto;
        }

        .box .btn {
            float: left;
            /* padding: 40px; */
            padding: 62px;
        }

        /* .box .box1 .car {
            float: right;
        } */

        .box .box1 {
            position: relative;
            float: right;
        }
        .box .box1 img{
            /* width数值 让效果 看着合适就行 */
           width: 160px;
           /* img距离右侧的距离,最好等于按钮距离父元素左侧的距离 */
           margin: 20px 62px 20px 0;
        }
        .box .box1 span {
            position: absolute;
            top: 10px;
            /* right: 3px; */
            right: 50px;
            display: block;
            width: 40px;
            height: 40px;
            background-color: red;
            border-radius: 50%;
            text-align: center;
            line-height: 40px;
            color: #fff;
        }

祝学习愉快!

0

0 学习 · 15276 问题

查看课程