老师,为什么我这里相邻的两元素外边距不会重叠呢?

老师,为什么我这里相邻的两元素外边距不会重叠呢?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
    * {
        padding: 0;
        margin: 0;
    }
 
    .container {
        width: 900px;
        height: 600px;
        background-color: white;
        margin: 0 auto;
    }
 
    .top {
        width: 900px;
        height: 350px;
        background: #63B8FF;
    }
 
    .img1 {
        width: 360px;
        height: 214px;
        background: url(http://img1.sycdn.imooc.com/climg//58c0f808000129a303600215.jpg) no-repeat;
        margin: 68px 60px;
    }
 
    .img2 {
        width: 360px;
        height: 214px;
        background: url(http://img1.sycdn.imooc.com/climg//58c0f819000198a703600214.jpg) no-repeat;
        margin: 68px 60px;
    }
 
    .top div {
        display: inline-block;
    }
 
    .bottom {
        width: 900px;
        height: 250px;
        background: #CD919E;
    }
    </style>
</head>
 
<body>
    <div class="container">
        <div class="top">
            <div class="img1">
            </div>
            <div class="img2"></div>
        </div>
        <div class="bottom">
            <div class="one"></div>
            <div class="two"></div>
            <div class="three"></div>
        </div>
    </div>
</body>
 
</html>


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

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

2回答
好帮手慕言 2019-06-13 13:45:20

同学你好,只有上下margin会重叠,左右方向的不会哦,

如果帮助到了你,欢迎采纳~祝学习愉快

好帮手慕言 2019-06-13 11:06:35

同学你好,因为设置了display: inline-block;解决了margin上下重叠的问题。

如果帮助到了你,欢迎采纳,祝学习愉快~

  • 提问者 拍拍你的头 #1
    在同一行了为什么左右的margin没有重叠呢?
    2019-06-13 11:15:40
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

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