我想在我正在构建的页面上有5个相等的列,我似乎无法理解5列网格在这里是如何使用的: http://web.archive.org/web/20120416024539/http://domain7.com/mobile/tools/bootstrap/responsive
上面演示的五列网格是twitter引导框架的一部分吗?
我想在我正在构建的页面上有5个相等的列,我似乎无法理解5列网格在这里是如何使用的: http://web.archive.org/web/20120416024539/http://domain7.com/mobile/tools/bootstrap/responsive
上面演示的五列网格是twitter引导框架的一部分吗?
当前回答
有人使用bootstrap-sass (v3),下面是使用bootstrap混合的5列的简单代码:
.col-xs-5ths {
@include make-xs-column(2.4);
}
@media (min-width: $screen-sm-min) {
.col-sm-5ths {
@include make-sm-column(2.4);
}
}
@media (min-width: $screen-md-min) {
.col-md-5ths {
@include make-md-column(2.4);
}
}
@media (min-width: $screen-lg-min) {
.col-lg-5ths {
@include make-lg-column(2.4);
}
}
确保你已经包括:
@import "bootstrap/variables";
@import "bootstrap/mixins";
其他回答
如果你不需要完全相同的列宽度,你可以尝试使用嵌套创建5列:
<div class="container">
<div class="row">
<div class="col-xs-5">
<div class="row">
<div class="col-xs-6 column">Column 1</div>
<div class="col-xs-6 column">Column 2</div>
</div>
</div>
<div class="col-xs-7">
<div class="row">
<div class="col-xs-4 column">Column 3</div>
<div class="col-xs-4 column">Column 4</div>
<div class="col-xs-4 column">Column 5</div>
</div>
</div>
</div>
</div>
斯菲德尔
前两列的宽度为5/12 * 1/2 ~ 20.83%
后三列:7/12 * 1/3 ~ 19.44%
这样的hack在许多情况下给出了可接受的结果,不需要任何CSS更改(我们只使用本机引导类)。
在我的例子中,仅仅使用col并没有得到正确的效果。所有项都将出现在彼此旁边,我不想用PHP计算出什么时候放置行元素。
那么如何创建一个类来扩展我们的引导col特性呢?如果人们想知道如何在不使用col类的情况下使5列与Bootstrap一起工作。
插件/ bootstrap.less:
@media @md {
.col-md-2-4 {
-ms-flex: 0 0 20%;
flex: 0 0 20%;
max-width: 20%;
}
}
我将其命名为.col-md-2-4,因为Bootstrap的12个网格布局除以5等于2.4。
现在你可以创建一个5列的布局。也可以与其他断点列类结合使用:
<div class="col-6 col-sm-4 col-md-2-4">
1/5 column
</div>
注意,我添加了一个媒体查询,语句周围的代码更少。因此,如果您想添加其他列断点类,请确保围绕它使用正确的媒体查询。
有人使用bootstrap-sass (v3),下面是使用bootstrap混合的5列的简单代码:
.col-xs-5ths {
@include make-xs-column(2.4);
}
@media (min-width: $screen-sm-min) {
.col-sm-5ths {
@include make-sm-column(2.4);
}
}
@media (min-width: $screen-md-min) {
.col-md-5ths {
@include make-md-column(2.4);
}
}
@media (min-width: $screen-lg-min) {
.col-lg-5ths {
@include make-lg-column(2.4);
}
}
确保你已经包括:
@import "bootstrap/variables";
@import "bootstrap/mixins";
5列布局与Twitter引导风格
.col-xs-15 {
position: relative;
min-height: 1px;
padding-right: 10px;
padding-left: 10px;
}
.col-xs-15 {
width: 100%;
float: left;
}
@media (min-width: 768px) {
.col-xs-15 {
width: 50%;
float: left;
}
}
@media (min-width: 992px) {
.col-xs-15 {
width: 20%;
float: left;
}
}
@media (min-width: 1200px) {
.col-xs-15 {
width: 20%;
float: left;
}
}
我对这个问题的首选方法是基于make-grid-columns mixin,利用现有的Bootstrap变量创建一个SASS mixin。
// Custom Grid Columns
//
// $name - determines the class names: eg. ".col-5ths, .col-sm-5ths ..."
// $size - determines the width (2.4 is one fifth of 12, the default number of columns)
@mixin custom-grid-columns($name, $size, $grid-columns: $grid-columns, $breakpoints: $grid-breakpoints) {
$columns: round($grid-columns / $size);
%custom-grid-column {
@include make-col-ready();
}
@each $breakpoint in map-keys($breakpoints) {
$infix: breakpoint-infix($breakpoint, $breakpoints);
.col#{$infix}-#{$name} {
@extend %custom-grid-column;
}
@include media-breakpoint-up($breakpoint, $breakpoints) {
// Create column
.col#{$infix}-#{$name} {
@include make-col($size);
}
// Create offset
@if not ($infix=="") {
.offset#{$infix}-#{$name} {
@include make-col-offset($size);
}
}
}
}
}
然后可以调用mixin来生成自定义列类和偏移量类。
@include custom-grid-columns('5ths', 2.4);