两个div并列挨着,左边的div的margin-right属性和右边的div的margin-left属性是一回事吗?

两个div并列挨着,左边的div的margin-right属性和右边的div的margin-left属性是一回事吗?

就像2楼那样,加上边框和背景色就能清楚的看到效果了。另外要注意的是,行内元素(如)和块级元素是有区别的,前者是margin-right和margin-left值的和,而后者是取较大值。

有本书《HTML+CSS网页设计与布局从入门到精通》可以看一下,第13章把原理讲得很清楚。

效果上是一回事

[code="html"]

        <div style="background-color:#FFF;border:1px solid #000;width:100px;height:100px;float:left;"></div>
        <div style="clear:both;"></div>
    </div>

    <div style="background-color:gray;margin-top:100px;padding:20px;">
        <div style="background-color:#FFF;border:1px solid #000;width:100px;height:100px;float:left;"></div>
        <div style="background-color:#FFF;border:1px solid #000;width:100px;height:100px;float:left;margin-left:10px;"></div>
        <div style="clear:both;"></div>
    </div>

[/code]

你在我右边100m 和 我在你左边100m的区别