【问题标题】:How to remove bootstrap padding in Chrome如何在 Chrome 中删除引导填充
【发布时间】:2014-08-04 09:14:55
【问题描述】:

我试图在页面中水平和垂直居中 div。这是实现的,但在 chrome 中有一些左右填充。这个怎么去掉。在 Firefox 中运行良好。

MyStyle.css:

html, body
{
  height:100%;
  margin:0;
  padding:0;
}

.container-fluid{
  height:100%;
  display:table;
  width: 100%;
  padding:0;  
}

.row-fluid 
{
  height: 100%; 
  display:table-cell; 
  vertical-align: middle;  
}

.centering {
  float:none;
  margin:0 auto;
}

// bootstrap css for .container-fluid
{
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

HTML:

<div class="container-fluid">
        <div class="row-fluid" style="background-color: blue">
            <div class="centering text-center col-lg-1" 
                 style="background-color: green">
                Yeah I'm centered
            </div>
        </div>
    </div>

蓝色没有填满chrome的页面,左右两边都有填充。

【问题讨论】:

  • 一些修改,但我终于让它工作了......见下文

标签: css twitter-bootstrap-3


【解决方案1】:

好的,我想通了。在 CSS 中添加了一个名为 content 的伪元素,这导致了此问题。在css: how to remove pseudo elements (after, before, ...) 的帮助下,我找到了一个解决方案,将其添加到您的 CSS 中:

.container-fluid:before{
    content:none;
}

.container-fluid:after{
     content:none;
}

并改变你的居中等级:

.centering {
  float:none;
  margin:0 auto;
  padding-left:0px;
  padding-right:0px;
}

Bootply Demo

【讨论】:

  • 删除绿色块中的填充。蓝色必须填满页面,但页面右侧 n 左侧有填充。向 body{} 添加 6px 左右填充。就是现在的样子
  • 那行得通。但我还必须添加一个类似的“之前”类来删除左侧的填充。非常感谢。
  • 是的,事后我意识到并更新了我的答案......我喜欢回答这些类型的问题,因为我学到了很多东西,我需要提高我的 CSS 知识
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-27
  • 1970-01-01
  • 1970-01-01
  • 2012-09-02
  • 1970-01-01
  • 2020-07-21
  • 2017-11-20
相关资源
最近更新 更多