2-14有需要改进的地方吗

来源:2-14 编程练习

Liiiu

2020-09-05 15:03:46

<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
 * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 80%;
            height: 800px;
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            right: 0;
            margin: auto auto;
        }

        .img-box {
            width: 100%;
            height: 500px;
            background-color: aquamarine;
        }

        .img-box-img {
            position: relative;
            width: 50%;
            height: 500px;
            float: left;
        }

        .img-box img {
            display: block;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -107px;
            margin-left: -180px;
        }

        .img-xob {
            width: 100%;
            height: 300px;
            background-color: pink;
        }

        .img-xob-img {
            position: relative;
            width: 33.3333%;
            height: 300px;
            float: left;
        }
        .img-xob-img img{
            display: block;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -30px;
            margin-left: -100px;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="img-box">
        <div class="img-box-img">
            <img src="http://climg.mukewang.com/58c0f808000129a303600215.jpg"/>
        </div>
        <div class="img-box-img">
            <img src="http://climg.mukewang.com/58c0f808000129a303600215.jpg"/>
        </div>
    </div>
    <div class="img-xob">
        <div class="img-xob-img">
            <img src="http://climg.mukewang.com/58c0f81d0001fe4402000060.jpg"/>
        </div>
        <div class="img-xob-img">
            <img src="http://climg.mukewang.com/58c0f8220001dfce02000060.jpg"/>
        </div>
        <div class="img-xob-img">
            <img src="http://climg.mukewang.com/58c0f8780001c74602000060.jpg"/>
        </div>
    </div>
</div>
</body>
</html>


写回答

1回答

好帮手慕星星

2020-09-05

同学你好,布局是可以的,但是间隙还需要调整。图片之间的间隙与图片和边界之间的间隙应该是相等的,而代码中实现是2倍的关系。参考修改

  • 最外层大盒子建议设置固定宽度,这样里面容易计算间距。不需要水平垂直显示,可以去掉

    http://img.mukewang.com/climg/5f533c000994d4ab03520277.jpg

  • 小盒子建议设置图片的宽度,然后计算小盒子的间距

    http://img.mukewang.com/climg/5f533c3309461f9503710429.jpg

    第二行也是这样计算的

    http://img.mukewang.com/climg/5f533c5409ffc87304130424.jpg

修改之后还可以减少代码,自己再测试下。

祝学习愉快!

0

0 学习 · 40143 问题

查看课程