CSS 2-14编程练习

CSS 2-14编程练习

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <style>

        * {

            margin: 0;

            padding: 0;

            box-sizing: border-box;

        }

        .top {

            width: 70%;

            height: 400px;

            margin: 0 auto;

            background: #9BE3FF;

        }

        .top .left {

            position: relative;

            float: left;

            width: 50%;

            height: 100%;

            line-height: 500px;

        }

        .top .right {

            position: relative;

            float: right;

            width: 50%;

            height: 100%;

        }

        .top img {

            position: absolute;

            top: 50%;

            margin-top: -107px;

            left: 50%;

            margin-left: -180px;

        }

        

        .bottom {

            width: 70%;

            height: 300px;

            margin: 0 auto;

            background: #FFC0CB;

        }

        .bottom .left {

            position: relative;

            float: left;

            width: 33.3%;

            height: 100%;

        }

        .bottom .middle {

            position: relative;

            float: left;

            width: 33.3%;

            height: 100%;

        }

        .bottom .right {

            position: relative;

            float: left;

            width: 33.3%;

            height: 100%;

        }

        .bottom img {

            position: absolute;

            top: 50%;

            margin-top: -30px;

            left: 50%;

            margin-left: -100px;

        }

    </style>

</head>

<body>

    <div class="top">

        <div class="left">

            <img src="http://img1.sycdn.imooc.com/climg//58c0f808000129a303600215.jpg">

        </div>

        <div class="right">

            <img src="http://img1.sycdn.imooc.com/climg//58c0f819000198a703600214.jpg">

        </div>

    </div>

    <div class="bottom">

        <div class="left">

            <img src="http://img1.sycdn.imooc.com/climg//58c0f81d0001fe4402000060.jpg">

        </div>

        <div class="middle">

            <img src="http://img1.sycdn.imooc.com/climg//58c0f8220001dfce02000060.jpg">

        </div>

        <div class="right">

            <img src="http://img1.sycdn.imooc.com/climg//58c0f8780001c74602000060.jpg">

        </div>

    </div>

</body>

</html>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕星星 2020-09-22 10:08:41

同学你好,代码布局是可以的,但是距离还需要调整。要求图片之间的距离与图片和边界的距离相等,现在是2倍的关系

http://img1.sycdn.imooc.com//climg/5f695a630948faef13460706.jpg

建议最外层大盒子设置固定宽度,小盒子设置与图片宽度一致,然后都左浮动,通过宽度去计算间距,参考

http://img1.sycdn.imooc.com//climg/5f695c4d096666e604380730.jpg

大盒子宽度是1200px,小盒子宽度为360px,那么一个间隙的宽度是(1200-360*2)/3=160px 。底部也是同样的计算

http://img1.sycdn.imooc.com//climg/5f695ca209c8954104480863.jpg

自己再测试下,祝学习愉快!

  • 提问者 青栲 #1
    收到,谢谢老师
    2020-09-22 10:42:14
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师