[英]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: 但是有一些问题/问题:
div
s do not fill up the window vertically, and the height of each block/ div
is not changed. div
s切勿垂直填满窗口,并且每个块/高度div
不改变。 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%
) 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:
因此,答案是:
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
内部的元素给定。
Look below. 往下看。
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%;
我们给
html
和body
元素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. 另外,不要直接在
span6
, row-fluid
等上直接设置高度。这仅是示例。 In live site, use some classes to override classes in bootstrap. 在实时站点中,使用某些类覆盖引导程序中的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.