css - 我的 div 从下到上排列,而不是从上到下排列

标签 css html

我有 6 种不同类型的 div、4 个容器和 2 个内容 div,内容 div 会多次打印不同的内容。

<div id="MainContainer">

      <div class="box_container">
        <div class="box_container_left">
          <div class="box_content_left">
             Test
          </div>
        </div>


        <div class="box_container_right">
          <div class="box_content_right">
             Test2
          </div>
        </div>
 </div>

如果 div 大小相同,则没有问题,布局看起来也符合预期,但如果我向 div 添加一行,或添加另一个内容 div,布局就会出错。

我做了一些测试,底部的 2 个 div 似乎是链接在一起的,从那一点开始上升。

.box_container{
        background-color:white;
        border: solid 3px black;
}

.box_container_left{
    position:relative;
    display:inline-block;
    width:40%;
    min-height:500px;
    background-color:red;
    border: solid 3px black;
}

.box_container_right{
    position:relative;
    display:inline-block;
    width:40%;
    min-height:500px;
    background-color:blue;
    border: solid 3px black;
}

.box_content_left{
    margin-top:3%;
    margin-left:10%;
    margin-right:10%;
    width:80%;
    background-color:green;
    min-height:20px;
    word-wrap: break-word;
    border: solid 3px black;
}

.box_content_right{
    margin-top:3%;
    margin-left:10%;
    margin-right:10%;
    width:80%;
    min-height:20px;
    background-color:purple;
    word-wrap: break-word;
    border: solid 3px black;
}

我没能找到问题所在,所以如果您知道问题出在哪里,我感谢您的帮助。

最佳答案

您只需要 float 您的box_container_left:

.box_container_left {
    float: left;
}

http://jsfiddle.net/2p32M/1/

关于css - 我的 div 从下到上排列,而不是从上到下排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21046404/

相关文章:

html - 使用 css 简单地居中一个对象,没有 hack

html - CSS - Margin-top 不适用于一个选择器,但在兼容模式下可以

javascript - 如何动态地将 <span> 标签附加到 <p> 标签的特定位置?

javascript - 如何设计打印窗口的表格?

html - 在图像上放置文本

html - 如何在 HTML、CSS 和 JS 中创建不接受点击但让它击中该层后面的阴影?

html - 垂直定位 : I want an element, x,垂直上方,y,在桌面上,垂直下方,y,在移动设备上

html - 表格单元格在行内的高度不同

javascript - 多行轮播居中

javascript - 使用 setInterval 更改背景