【问题标题】:Align two DIV's and use entire page width对齐两个 DIV 并使用整个页面宽度
【发布时间】:2010-10-29 15:28:33
【问题描述】:

我需要在父 div 中对齐两个 div。

父div应该占据页面宽度,两边都有边距。

第一个子 div 的宽度应为 100 像素,边距为 4 像素。第二个子 div 必须占据其余空间,右侧有 4px 的边距。

如何为此编写 CSS?我已经写到这里了

div.parent {

        width: ?;

        border:1px black solid;

        position: relative;

        clear: both;

        }

<div class="parent">

<div class="child1"> </div>

<div class="child2"> </div>

【问题讨论】:

  • 这里的人不喜欢为你编写代码。用你到目前为止提出的代码更新你的问题,以及关于你遇到的任何问题的具体问题。
  • 你应该在“CSS 2 column layout”上搜索一下,你会发现很多信息来解决这个布局问题。
  • 我不知道如何让父级带边距占据整个页面宽度

标签: css


【解决方案1】:

为什么不直接给父 div 添加边距?

<div style="height: 100px; width: 100%; padding: 4px; background-color: Yellow;">
    <div style="height: 100%; width: 100px; background-color: Lime; position: relative; float: left; border: solid 1px black; border-right-width: 0px;"></div>
    <div style="height: 100%; width: 100%; background-color: Red; border: solid 1px black; border-left-width: 0px;"></div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 2011-01-02
    • 2015-07-12
    • 2012-09-03
    • 2014-06-28
    • 1970-01-01
    • 2021-07-30
    相关资源
    最近更新 更多