简体   繁体   English

将div的列与bootstrap 2中的流体布局对齐

[英]align columns of divs with fluid layout in bootstrap 2

I made a simple two-column fluid layout using Bootstrap 2 . 我使用Bootstrap 2进行了简单的两列流体布局。 One column contains two div , and the other contains three div . 一列包含两个div ,另一列包含三个div Both columns are of span6 . 两列均为span6 The fiddle is here . 小提琴在这里

I attempted to adjust the heights of the two div s in the left column using CSS, so that the top one occupies 62.5% of the browser window height, while the bottom one occupies the rest 37.5%. 我尝试使用CSS调整左列中两个div的高度,以使顶部的一个占浏览器窗口高度的62.5%,而底部的一个占浏览器窗口高度的37.5%。 And similarly for the three div s in the right column. 同样地,对于三个div在右列秒。 But there are a few questions/problems: 但是有一些问题/问题:

  1. The heights of the blocks/ div s do not fill up the window vertically, and the height of each block/ div is not changed. 块/的高度div s切勿垂直填满窗口,并且每个块/高度div不改变。
  2. How to make the total height of the two div s on the left equal to that of the three div s on the right, while respecting the relative height ratio within each column ( left: 62.5%, 37.5%; right: 35%, 30%, 35% ) 如何在尊重各列内的相对高度比的同时,使左侧的两个div的总高度等于右侧的三个div的总高度( left: 62.5%, 37.5%; right: 35%, 30%, 35%
  3. How to adjust the paddings between blocks/ div s? 如何调整块/ div之间的填充?

I hope all of these can be achieved without any Javascript. 我希望所有这些都可以在没有任何Javascript的情况下实现。

I've tried something, I hope that helps you. 我尝试了一些东西,希望对您有所帮助。 So, answers are: 因此,答案是:

  1. Height of each BlocX div is not changed because you didn't set height of body . 每个BlocX div的高度都不会更改,因为您没有设置body高度。 In tour case, body have auto height, given by elements inside of body . 在巡回案例中,车身具有自动高度,由body内部的元素给定。

  2. Look below. 往下看。

  3. Those "paddings" are actually margins in class .well . 这些“填充”实际上是.well类中的空白。 So, avoid that class or override settings. 因此,请避免使用该类或覆盖设置。

Finally, we have code like this: 最后,我们有如下代码:

HTML: HTML:

Removed class .well , everything else is the same. 删除类.well ,其他所有内容都相同。

CSS: CSS:

html{height:100%;}

.body-background {
    padding-top: 10px;
    background-color: #D1D1D1;
    height:100%;
}
.container-fluid, .row-fluid, .span6
{
    height:100%;
}

#A-b {
    min-height: 62.5%;
    height: 62.5%;
    background-color: #FFE0C2;
}

#B-b {
    min-height: 37.5%;
    height: 37.5%;
    background-color: #4D4D4D;
}

#C-b {
    min-height: 35%;
    height: 35%;
    background-color: #969696;
}

#D-b {
    min-height: 30%;
    height: 30%;
    background-color: #57BCFF;
}

#E-b {
    min-height: 35%;
    height: 35%;
    background-color: #183547;
}

We give to html and body elements height:100%; 我们给htmlbody元素height:100%; and after that do the same to .container-fluid , .row-fluid and .span6 . 之后,对.container-fluid.row-fluid.span6 Now we have result like this in DEMO . 现在我们在DEMO中得到了这样的结果。

NOTE: In resolutions smaller than 768px, use media queries to set height of BlockX and all other elements. 注意:在小于768像素的分辨率中,使用媒体查询来设置BlockX和所有其他元素的高度。 Also, don't set height directly on span6 , row-fluid etc. This is just example. 另外,不要直接在span6row-fluid等上直接设置高度。这仅是示例。 In live site, use some classes to override classes in bootstrap. 在实时站点中,使用某些类覆盖引导程序中的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM