从引导3中的列中删除填充

问题:

在引导3中删除col-md-*的左右边距。

HTML代码:

<div class="col-md-12">
<h2>OntoExplorer<span style="color:#b92429">.</span></h2>


<div class="col-md-4">
<div class="widget">
<div class="widget-header">
<h3>Dimensions</h3>
</div>


<div class="widget-content" id="">
<div id='jqxWidget'>
<div style="clear:both;margin-bottom:20px;" id="listBoxA"></div>
<div style="clear:both;" id="listBoxB"></div>


</div>
</div>
</div>
</div>


<div class="col-md-8">
<div class="widget">
<div class="widget-header">
<h3>Results</h3>
</div>


<div class="widget-content">
<div id="map_canvas" style="height: 362px;"></div>
</div>
</div>
</div>


</div>

期望的输出:

目前,这段代码在两列的右侧和左侧添加了填充/边距。我在想,为了去掉两边的多余空间,我错过了什么?

注意:

如果我删除“col-md-4”,那么两列展开到100%,但我希望它们彼此相邻。

895967 次浏览

你可以创建一个新的类来删除边距,并应用于你想要删除额外边距的元素:

.margL0 { margin-left:0 !important }

重要的!:它将帮助您删除默认的保证金或覆盖当前的保证金值

并应用于您想要从左侧删除边缘的div

你通常会使用.row来包装两列,而不是.col-md-12——那是一列包装另一列。毕竟,.row没有col-md-12会带来的额外的边距和填充,并且还折扣了一个列将引入的负左&正确的利润率。

<div class="container">
<div class="row">
<h2>OntoExplorer<span style="color:#b92429">.</span></h2>


<div class="col-md-4 nopadding">
<div class="widget">
<div class="widget-header">
<h3>Dimensions</h3>
</div>
<div class="widget-content">
</div>
</div>
</div>


<div class="col-md-8 nopadding">
<div class="widget">
<div class="widget-header">
<h3>Results</h3>
</div>
<div class="widget-content">
</div>
</div>
</div>
</div>
</div>

如果真的想要删除边距/边距,则添加一个类来过滤每个子列的边距/边距。

.nopadding {
padding: 0 !important;
margin: 0 !important;
}

引导4添加了.no-gutters类

引导3.4添加了.row-no-gutters类

引导3:我总是把这个风格添加到我的Bootstrap LESS / SASS:

.row-no-padding {
[class*="col-"] {
padding-left: 0 !important;
padding-right: 0 !important;
}
}

然后在HTML中你可以写:

<div class="row row-no-padding">

如果你只想瞄准子列,你可以使用子选择器(感谢John Wu)。

.row-no-padding > [class*="col-"] {
padding-left: 0 !important;
padding-right: 0 !important;
}

你也可以只移除某些设备尺寸的填充(例如SASS):

/* Small devices (tablets, 768px and up) */
@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max) {
.row-sm-no-padding {
[class*="col-"] {
padding-left: 0 !important;
padding-right: 0 !important;
}
}
}

如果您希望媒体查询向上支持小型设备,可以删除媒体查询的max-width部分。

[class*="col-"]
padding: 0
margin: 0

特别针对SASS mixin:

@mixin no-padding($side) {
@if $side == 'all' {
.no-padding {
padding: 0 !important;
}
} @else {
.no-padding-#{$side} {
padding-#{$side}: 0 !important;
}
}
}


@include no-padding("left");
@include no-padding("right");
@include no-padding("top");
@include no-padding("bottom");
@include no-padding("all");

然后在HTML中,你可以使用

.no-padding-left
.no-padding-right
.no-padding-bottom
.no-padding-top
.no-padding - to remove padding from all sides

当然,您可以@只包含您需要的那些声明。

另一种解决方案(仅在从bootstrap的LESS源编译bootstrap时可行)是重新定义为列设置填充的变量。

你会在variables.less文件中找到这个变量:它被称为@grid-gutter-width

资料中是这样描述的:

//** Padding between columns. Gets divided in half for the left and right.
@grid-gutter-width:         30px;

将其设置为0,编译bootstrap.less,并包含结果bootstrap.css。你完成了。如果您像我一样已经在使用引导源,那么它可以作为定义附加规则的替代方法。

只减少列上的填充物不会达到目的,因为你会扩大页面的宽度,使它与页面的其他部分不均匀,比如导航栏。你需要同样地减少行上的负边距。以@martinedwards的LESS为例:

.row-no-padding {
margin-left: 0;
margin-right: 0;
[class*="col-"] {
padding-left: 0 !important;
padding-right: 0 !important;
}
}

以上的解决方案都不适合我。遵循这个答案,我能够创建一些适合我的东西。在这里,我还使用了一个媒体查询,以限制这只小屏幕。

@media (max-width: @screen-sm) {
[class*="col-"] {
padding-left: 0;
padding-right: 0;
}
.row {
margin-left: 0;
margin-right: 0;
}
.container-fluid {
margin: 0;
padding: 0;
}
}
<div class="col-md-12">
<h2>OntoExplorer<span style="color:#b92429">.</span></h2>


<div class="col-md-4">
<div class="widget row">
<div class="widget-header">
<h3>Dimensions</h3>
</div>


<div class="widget-content" id="">
<div id='jqxWidget'>
<div style="clear:both;margin-bottom:20px;" id="listBoxA"></div>
<div style="clear:both;" id="listBoxB"></div>


</div>
</div>
</div>
</div>


<div class="col-md-8">
<div class="widget row">
<div class="widget-header">
<h3>Results</h3>
</div>


<div class="widget-content">
<div id="map_canvas" style="height: 362px;"></div>
</div>
</div>
</div>

您可以在col-md-4内的div中添加一个类row,行的-15px边缘将平衡列的沟槽。好的解释在这里关于水槽和排在Bootstrap 3。

<style>
.col-md-12{
padding-left:0px !important;
padding-right:0px !important;
}
.col-md-8{
padding-left:0px !important;
padding-right:0px !important;
}
.col-md-4{
padding-left:0px !important;
padding-right:0px !important;
}
</style>

你可以使用bootstrap创建更少的Mixins来管理你的列的边距和填充,

< a href = " http://mohandere。工作/ less-mixins-for-margin-and-padding-with-bootstrap-3 " rel = " http://mohandere.work/less-mixins-for-margin-and-padding-with-bootstrap-3/ nofollow”> < / >

用法:

xs-padding-lr-15px//left right both
xs-padding-l-15px
xs-padding-r-15px

类似地,设置边距/填充为0,你可以使用,

xs-padding-lr-0px
xs-padding-l-0px
xs-padding-r-0px

我想直接用更简单

margin:-30px;

重写通过引导设置的原始值。

我试过了

margin: 0px -30px 0px -30px;

这对我很有效。

维塔利·西林的回答是上构建。不仅包括我们根本不需要填充的情况,还包括我们有标准大小填充的情况。

在sassmeister.com上查看此代码到CSS的实时转换

@mixin padding($side, $size) {
$padding-size : 0;
@if $size == 'xs' { $padding-size : 5px; }
@else if $size == 's' { $padding-size : 10px; }
@else if $size == 'm' { $padding-size : 15px; }
@else if $size == 'l' { $padding-size : 20px; }


@if $side == 'all' {
.padding--#{$size} {
padding: $padding-size !important;
}
} @else {
.padding-#{$side}--#{$size} {
padding-#{$side}: $padding-size !important;
}
}
}


$sides-list: all top right bottom left;
$sizes-list: none xs s m l;
@each $current-side in $sides-list {
@each $current-size in $sizes-list {
@include padding($current-side,$current-size);
}
}

然后输出:

.padding--none {
padding: 0 !important;
}


.padding--xs {
padding: 5px !important;
}


.padding--s {
padding: 10px !important;
}


.padding--m {
padding: 15px !important;
}


.padding--l {
padding: 20px !important;
}


.padding-top--none {
padding-top: 0 !important;
}


.padding-top--xs {
padding-top: 5px !important;
}


.padding-top--s {
padding-top: 10px !important;
}


.padding-top--m {
padding-top: 15px !important;
}


.padding-top--l {
padding-top: 20px !important;
}


.padding-right--none {
padding-right: 0 !important;
}


.padding-right--xs {
padding-right: 5px !important;
}


.padding-right--s {
padding-right: 10px !important;
}


.padding-right--m {
padding-right: 15px !important;
}


.padding-right--l {
padding-right: 20px !important;
}


.padding-bottom--none {
padding-bottom: 0 !important;
}


.padding-bottom--xs {
padding-bottom: 5px !important;
}


.padding-bottom--s {
padding-bottom: 10px !important;
}


.padding-bottom--m {
padding-bottom: 15px !important;
}


.padding-bottom--l {
padding-bottom: 20px !important;
}


.padding-left--none {
padding-left: 0 !important;
}


.padding-left--xs {
padding-left: 5px !important;
}


.padding-left--s {
padding-left: 10px !important;
}


.padding-left--m {
padding-left: 15px !important;
}


.padding-left--l {
padding-left: 20px !important;
}

有时可能会丢失列所需的填充。它们最终会粘在一起。为了防止这种情况,你可以像下面这样更新类:

<div class="col-md-3 NoPaddingForChildren">
<div class="col-md-6">
<label>Id</label>
<input ng-model="ID" class="form-control">
</div>
<div class="col-md-6">
<label>Value</label>
<input ng-model="Val" class="form-control">
</div>
</div>

及对应类:

.NoPaddingForChildren > div:not(:first-child):not(:last-child) {
padding-left: 0;
padding-right: 0;
}


.NoPaddingForChildren > div:first-child {
padding-left: 0;
}


.NoPaddingForChildren > div:last-child {
padding-right: 0;
}

简单地添加“没有护垫”,它是bootstrap 3中的内置类

将你的列包装成一个.row,并在这个div中添加一个名为no-gutter的类

<div class="container">
<div class="row no-gutter">
<h2>OntoExplorer<span style="color:#b92429">.</span></h2>


<div class="col-md-4">
<div class="widget">
<div class="widget-header">
<h3>Dimensions</h3>
</div>
<div class="widget-content">
</div>
</div>
</div>


<div class="col-md-8">
<div class="widget">
<div class="widget-header">
<h3>Results</h3>
</div>
<div class="widget-content">
</div>
</div>
</div>
</div>

然后将下面的内容粘贴到您的CSS文件

.row.no-gutter {
margin-left: 0;
margin-right: 0;
}


.row.no-gutter [class*='col-']:not(:first-child),
.row.no-gutter [class*='col-']:not(:last-child) {
padding-right: 0;
padding-left: 0;
}
用css删除/自定义Bootstrap Gutter 参考:http://arnique.net/web-design/58/a-quick-guide-to-changing-bootstraps-gutter-width/ < / p >

/* remove */
.gutter-0.row {
margin-right: -0px;
margin-left: -0px;
}
.gutter-0 > [class^="col-"], .gutter-0 > [class^=" col-"] {
padding-right: 0px;
padding-left: 0px;
}


/* customize */
.gutter-6.row {
margin-right: -3px;
margin-left: -3px;
}
.gutter-6 > [class^="col-"], .gutter-6 > [class^=" col-"] {
padding-right: 3px;
padding-left: 3px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row gutter-6">
<div class="col-sm-3 col-md-3">
<div class="thumbnail">
<img width="100%" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTcxIiBoZWlnaHQ9IjE4MCIgdmlld0JveD0iMCAwIDE3MSAxODAiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjwhLS0KU291cmNlIFVSTDogaG9sZGVyLmpzLzEwMCV4MTgwCkNyZWF0ZWQgd2l0aCBIb2xkZXIuanMgMi42LjAuCkxlYXJuIG1vcmUgYXQgaHR0cDovL2hvbGRlcmpzLmNvbQooYykgMjAxMi0yMDE1IEl2YW4gTWFsb3BpbnNreSAtIGh0dHA6Ly9pbXNreS5jbwotLT48ZGVmcz48c3R5bGUgdHlwZT0idGV4dC9jc3MiPjwhW0NEQVRBWyNob2xkZXJfMTU5MzRlYTgxN2QgdGV4dCB7IGZpbGw6I0FBQUFBQTtmb250LXdlaWdodDpib2xkO2ZvbnQtZmFtaWx5OkFyaWFsLCBIZWx2ZXRpY2EsIE9wZW4gU2Fucywgc2Fucy1zZXJpZiwgbW9ub3NwYWNlO2ZvbnQtc2l6ZToxMHB0IH0gXV0+PC9zdHlsZT48L2RlZnM+PGcgaWQ9ImhvbGRlcl8xNTkzNGVhODE3ZCI+PHJlY3Qgd2lkdGg9IjE3MSIgaGVpZ2h0PSIxODAiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSI2MSIgeT0iOTQuNSI+MTcxeDE4MDwvdGV4dD48L2c+PC9nPjwvc3ZnPg==" alt="">
<div class="caption">
<h3>Thumbnail label</h3>
<p>more</p>
<p><a href="#" class="btn btn-primary" role="button">Button</a> <a href="#" class="btn btn-default" role="button">Button</a></p>
</div>
</div>
</div>
<div class="col-sm-3 col-md-3">
<div class="thumbnail">
<img width="100%" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTcxIiBoZWlnaHQ9IjE4MCIgdmlld0JveD0iMCAwIDE3MSAxODAiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjwhLS0KU291cmNlIFVSTDogaG9sZGVyLmpzLzEwMCV4MTgwCkNyZWF0ZWQgd2l0aCBIb2xkZXIuanMgMi42LjAuCkxlYXJuIG1vcmUgYXQgaHR0cDovL2hvbGRlcmpzLmNvbQooYykgMjAxMi0yMDE1IEl2YW4gTWFsb3BpbnNreSAtIGh0dHA6Ly9pbXNreS5jbwotLT48ZGVmcz48c3R5bGUgdHlwZT0idGV4dC9jc3MiPjwhW0NEQVRBWyNob2xkZXJfMTU5MzRlYTgxN2QgdGV4dCB7IGZpbGw6I0FBQUFBQTtmb250LXdlaWdodDpib2xkO2ZvbnQtZmFtaWx5OkFyaWFsLCBIZWx2ZXRpY2EsIE9wZW4gU2Fucywgc2Fucy1zZXJpZiwgbW9ub3NwYWNlO2ZvbnQtc2l6ZToxMHB0IH0gXV0+PC9zdHlsZT48L2RlZnM+PGcgaWQ9ImhvbGRlcl8xNTkzNGVhODE3ZCI+PHJlY3Qgd2lkdGg9IjE3MSIgaGVpZ2h0PSIxODAiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSI2MSIgeT0iOTQuNSI+MTcxeDE4MDwvdGV4dD48L2c+PC9nPjwvc3ZnPg==" alt="">
<div class="caption">
<h3>Thumbnail label</h3>
<p>more</p>
<p><a href="#" class="btn btn-primary" role="button">Button</a> <a href="#" class="btn btn-default" role="button">Button</a></p>
</div>
</div>
</div>
<div class="col-sm-3 col-md-3">
<div class="thumbnail">
<img width="100%" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTcxIiBoZWlnaHQ9IjE4MCIgdmlld0JveD0iMCAwIDE3MSAxODAiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjwhLS0KU291cmNlIFVSTDogaG9sZGVyLmpzLzEwMCV4MTgwCkNyZWF0ZWQgd2l0aCBIb2xkZXIuanMgMi42LjAuCkxlYXJuIG1vcmUgYXQgaHR0cDovL2hvbGRlcmpzLmNvbQooYykgMjAxMi0yMDE1IEl2YW4gTWFsb3BpbnNreSAtIGh0dHA6Ly9pbXNreS5jbwotLT48ZGVmcz48c3R5bGUgdHlwZT0idGV4dC9jc3MiPjwhW0NEQVRBWyNob2xkZXJfMTU5MzRlYTgxN2QgdGV4dCB7IGZpbGw6I0FBQUFBQTtmb250LXdlaWdodDpib2xkO2ZvbnQtZmFtaWx5OkFyaWFsLCBIZWx2ZXRpY2EsIE9wZW4gU2Fucywgc2Fucy1zZXJpZiwgbW9ub3NwYWNlO2ZvbnQtc2l6ZToxMHB0IH0gXV0+PC9zdHlsZT48L2RlZnM+PGcgaWQ9ImhvbGRlcl8xNTkzNGVhODE3ZCI+PHJlY3Qgd2lkdGg9IjE3MSIgaGVpZ2h0PSIxODAiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSI2MSIgeT0iOTQuNSI+MTcxeDE4MDwvdGV4dD48L2c+PC9nPjwvc3ZnPg==" alt="">
<div class="caption">
<h3>Thumbnail label</h3>
<p>more</p>
<p><a href="#" class="btn btn-primary" role="button">Button</a> <a href="#" class="btn btn-default" role="button">Button</a></p>
</div>
</div>
</div>
<div class="col-sm-3 col-md-3">
<div class="thumbnail">
<img width="100%" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTcxIiBoZWlnaHQ9IjE4MCIgdmlld0JveD0iMCAwIDE3MSAxODAiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjwhLS0KU291cmNlIFVSTDogaG9sZGVyLmpzLzEwMCV4MTgwCkNyZWF0ZWQgd2l0aCBIb2xkZXIuanMgMi42LjAuCkxlYXJuIG1vcmUgYXQgaHR0cDovL2hvbGRlcmpzLmNvbQooYykgMjAxMi0yMDE1IEl2YW4gTWFsb3BpbnNreSAtIGh0dHA6Ly9pbXNreS5jbwotLT48ZGVmcz48c3R5bGUgdHlwZT0idGV4dC9jc3MiPjwhW0NEQVRBWyNob2xkZXJfMTU5MzRlYTgxN2QgdGV4dCB7IGZpbGw6I0FBQUFBQTtmb250LXdlaWdodDpib2xkO2ZvbnQtZmFtaWx5OkFyaWFsLCBIZWx2ZXRpY2EsIE9wZW4gU2Fucywgc2Fucy1zZXJpZiwgbW9ub3NwYWNlO2ZvbnQtc2l6ZToxMHB0IH0gXV0+PC9zdHlsZT48L2RlZnM+PGcgaWQ9ImhvbGRlcl8xNTkzNGVhODE3ZCI+PHJlY3Qgd2lkdGg9IjE3MSIgaGVpZ2h0PSIxODAiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSI2MSIgeT0iOTQuNSI+MTcxeDE4MDwvdGV4dD48L2c+PC9nPjwvc3ZnPg==" alt="">
<div class="caption">
<h3>Thumbnail label</h3>
<p>more</p>
<p><a href="#" class="btn btn-primary" role="button">Button</a> <a href="#" class="btn btn-default" role="button">Button</a></p>
</div>
</div>
</div>
</div>

如果你下载了带有SASS文件的bootstrap,你将能够编辑配置文件,其中设置了列的边距,然后保存它,这样SASS就会计算出列的新宽度

此后仅可在Bootstrap 4

<div class="p-0 m-0">
</div>

注意:.p-0和.m-0已经添加了bootstrap.css

您可以自定义引导网格系统并定义自定义响应网格。

将以下沟槽宽度的默认值从@grid-gutter-width = 30px更改为@grid-gutter-width = 0px

(沟槽宽度是列之间的填充物。它被分成了左右两半。)

Bootstrap 4有类.no-gutters,可以添加到row元素中。

<div class="container-fluid">
<div class="row no-gutters">
<div class="col-md-12">
[YOUR CONTENT HERE]
</div>
</div>
</div>

参考:http://getbootstrap.com/docs/4.0/layout/grid/#grid-options

引导4有一个原生类来做这件事:将类.no-gutters添加到父类.row

使用3.7.7或更小的引导程序删除b/w列的间距。

.no-gutter是一个自定义类,可以添加到行div中

.no-gutter > [class*='col-'] {
padding-right:0;
padding-left:0;
}

自版本3.4.0起,引导3有一个正式的删除填充的方法:类row-no-gutters

文档中的示例:

<div class="row row-no-gutters">
<div class="col-xs-12 col-md-8">.col-xs-12 .col-md-8</div>
<div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
</div>
<div class="row row-no-gutters">
<div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
<div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
<div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
</div>
<div class="row row-no-gutters">
<div class="col-xs-6">.col-xs-6</div>
<div class="col-xs-6">.col-xs-6</div>
</div>

你可以用叉子

https://github.com/srghma/bootstrap-rubygem-without-gutter/commit/8e42c16dcc2f132af3489c2275dd7460b524d437

gem "bootstrap", github: "srghma/bootstrap-rubygem-without-gutter"

我仍然喜欢控制每个屏幕大小的每个填充,所以这个css可能对你们有用:)

.nopadding-lg {
padding-left: 0!important;
padding-right: 0!important;
}
.nopadding-left-lg {padding-left: 0!important;}
.nopadding-right-lg {padding-right: 0!important;}


@media (max-width: 576px) {
.nopadding-xs {
padding-left: 0!important;
padding-right: 0!important;
}
.nopadding-left-xs {padding-left: 0!important;}
.nopadding-right-xs {padding-right: 0!important;}
}


@media (max-width: 768px) {
.nopadding-sm {
padding-left: 0!important;
padding-right: 0!important;
}
.nopadding-left-sm {padding-left: 0!important;}
.nopadding-right-sm {padding-right: 0!important;}
}
@media (max-width: 992px) {
.nopadding-md {
padding-left: 0!important;
padding-right: 0!important;
}
.nopadding-left-md {padding-left: 0!important;}
.nopadding-right-md {padding-right: 0!important;}
}