Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
努力在CSS中对齐div_Css_Html_Css Float - Fatal编程技术网

努力在CSS中对齐div

努力在CSS中对齐div,css,html,css-float,Css,Html,Css Float,我的代码如下所示 就我的一生而言,我无法让他们按照我所希望的方式排列。通过查看代码,可以很容易地看到每个div应该位于何处,但这里还有一些帮助: | topLeft | topRight | | ----------------------------------| right | | bottomLeft | bottomRight | | 请帮我做这个 我在子元素上使用绝对定位,在容器上使用相对定位,只

我的代码如下所示

就我的一生而言,我无法让他们按照我所希望的方式排列。通过查看代码,可以很容易地看到每个div应该位于何处,但这里还有一些帮助:

|  topLeft      |    topRight      |          |
 ----------------------------------|   right  |
| bottomLeft    |   bottomRight    |          |

请帮我做这个

我在子元素上使用绝对定位,在容器上使用相对定位,只要知道元素的尺寸(以px或%为单位),就很容易做到这一点

查看更新的小提琴:


(请注意,容器上的“相对位置”(position relative)属性正好使a)其中绝对定位的元素相对于容器进行定位。b) 它尊重你的利润0自动;(如果你给它一个位置:绝对的话,它不会这样做)

你的html代码中的主要问题,只是一个div标签的顺序

<div class="container">
    <div class="right">right</div> <!-- replaced top with right -->
                                   <!-- your mistake was fixed here -->
    <div class="top'">
        <div class="topRight">topRight</div>
        <div class="topLeft">topLeft</div>
    </div>

    <div class="bottom">
        <div class="bottomRight">bottomRight</div>
        <div class="bottomLeft">BottomLeft</div>
    </div>
</div>

例1。在左侧前面交换右侧位置:

html:

它将使右框向左浮动,与左框相对。 有更多的可能性,但都是关于理解
float
的功能,玩它吧


另一方面,在指定固定块时,您可以安全地舍弃
display:inline

Like?如果您有困难,您可以使用表格布局轻松完成此操作?太棒了!谢谢:-)
<div class="container">
    <div class="right">right</div> <!-- replaced top with right -->
                                   <!-- your mistake was fixed here -->
    <div class="top'">
        <div class="topRight">topRight</div>
        <div class="topLeft">topLeft</div>
    </div>

    <div class="bottom">
        <div class="bottomRight">bottomRight</div>
        <div class="bottomLeft">BottomLeft</div>
    </div>
</div>
//Css Style
.container {
    background: cyan;
    margin: 0 auto;
    width: 500px;
    height: 100px;
}
.top {
    background: purple;
    float: left;
    width: 400px;
    height: 80px;
}
.topLeft {
    background: green;
    display: inline;
    float: left;
    width: 300px;
    height: 80px;
}
.topRight {
    background: gray;
    display: inline;
    float: right;
    width: 100px;
    height: 80px;
}
.bottom {
    background: black;
    display: inline;
    float: left;
    width: 400px;
    height: 20px;
}
.BottomLeft {
    background: blue;
    display: inline;
    float: left;
    width: 300px;
    height: 20px;
}
.bottomRight {
    background: red;
    display: inline;
    float: right;
    width: 100px;
    height: 20px;
}
.right {
    background: yellow;
    display: inline;
    float: right;
    width: 100px;
    height: 100px;
}
<div class="top">
    <div class="topRight">
        topRight
    </div>
    <div class="topLeft">
        topLeft
    </div>
</div>
.topLeft {
  background: green;
  float: left;
  width: 300px;
  height: 80px;
} 
.topRight {
  background: gray;
  float: left;
  width: 100px;
  height: 80px;
}