【问题标题】:CSS/HTML: 2 Div's near each other with the second one's margin-left starting from the place the first div doesCSS / HTML:2个div彼此靠近,第二个div从第一个div所在的位置开始
【发布时间】:2014-09-10 08:48:06
【问题描述】:

是的,所以我有两个彼此靠近的 div。

第一个 div 只是站在那里,宽度为:400px; 然后是另一个 div 使用 width: 400px; float:left 和 margin-left: 10%;;让它靠近它。

主要问题是,当我调整页面大小时,它在它下面(这是我想要的),但它从第二个 div 开始 10%,所以第二个 div 不在第一个 div 下。

我该怎么办?

【问题讨论】:

    标签: html css


    【解决方案1】:

    已经解决了这个问题,所以让第一个 DIV 向右浮动,诀窍是转储 margin-right(有时 margin 会被窃听)并使用 padding-right: 10%;。我要感谢 Katstevens 的宝贵时间。

    【讨论】:

    • 请注意,使用填充而不是边距可能会导致其他问题,尤其是在您使用宽度和/或设置背景颜色时(在后一种情况下不会感知到边距)。很高兴听到你解决了它:)
    【解决方案2】:

    我会将margin-right: 10% 添加到第一个div 中。然后他们会正确排列。

    【讨论】:

    • 仍然不能解决我的问题,因为在第一个 div 和第二个 div 之间我需要有一些空间,所以需要左边距。
    • Div1 是否有 margin-right 或 Div2 是否有 margin-left 没有区别:无论哪种方式,它们之间都有一个边距。
    猜你喜欢
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 2017-03-12
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    相关资源
    最近更新 更多