设置div之间的空间 [英] Set space between divs

查看:91
本文介绍了设置div之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个这样的div:

I have two divs like this:

<section id="main">
        <div id="left">
            <asp:ContentPlaceHolder ID="left" runat="server" />
        </div>
        <div id="right">
            <asp:ContentPlaceHolder ID="right" runat="server" />
        </div>
</section>

这是我的CSS:

#left
{
    float: left;
    margin-right: 17px;

}

#right
{
    float: right;
}

我希望div之间的间隔为40px.我尝试在css中添加填充,边距和宽度,但是我认为它没有将填充设置为正确的40px.怎么做?

I want the space between the divs to be 40px. I tried adding padding, margin and width in my css, but I think it didn't set the padding to correct 40px. How to do it?

推荐答案

以相同的方式浮动它们,并添加40px的边距.如果您有2个元素以相反的方式浮动,那么您将受到更少的控制,而包含元素将决定它们之间的距离.

Float them both the same way and add the margin of 40px. If you have 2 elements floating opposite ways you will have much less control and the containing element will determine how far apart they are.

#left{
    float: left;
    margin-right: 40px;
}
#right{
   float: left;
}

这篇关于设置div之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆