【问题标题】:container-fluid in Bootstrap 3.4 not stretching horizontally 100%Bootstrap 3.4 中的容器流体未水平拉伸 100%
【发布时间】:2016-08-20 08:11:25
【问题描述】:

我遇到了与上一个问题相同的问题:div doesn't expand all the way horizontally

我的render() 函数中只有

render() {
    return (
        <div className="container intro-body">
        </div>
    )

intro-body 的 CSS 就像这样(用于颜色)

.intro-body {
    height: 582px;
    background-color: #3BC5C3;
}

在 13 英寸 Macbook 上全屏显示时,左右两侧为空白。似乎有某种填充或边距。

但是当我将窗口缩小到大约一半大小时,它会到达左右两侧

有人能解释一下这个奇怪的现象吗?这是 Bootstrap 中我不知道的东西吗?有人告诉我使用 container-fluid 但 1。我认为它已在 Bootstrap 3 和 2 中删除。我尝试时它没有用。

【问题讨论】:

    标签: javascript html css twitter-bootstrap


    【解决方案1】:

    如果您查看bootstrap source,您会看到.container 对每个媒体断点都有固定宽度,除了超小型设备,.container-fluid 对所有媒体断点都有完整宽度:

    .container {
        padding-right: 15px;
        padding-left: 15px;
        margin-right: auto;
        margin-left: auto;
    }
    @media (min-width: 768px) {
        .container {
            width: 750px;
        }
    }
    @media (min-width: 992px) {
        .container {
            width: 970px;
        }
    }
    @media (min-width: 1200px) {
        .container {
            width: 1170px;
        }
    }
    .container-fluid {
        padding-right: 15px;
        padding-left: 15px;
        margin-right: auto;
        margin-left: auto;
    }
    

    因此,如果您想为每个媒体断点设置全角,请使用.container-fluid

    【讨论】:

    • 好的,我正在使用container-fluid。我在某处读到使用row (它有-15 个边距并且将抵消容器流体的默认边距)就足够了,但它不起作用。有解决办法吗?
    • 是的,.row 添加负左/右页边距,这很好。要“修复”它,您必须使用引导程序 .col- 元素。因此,要正确使用引导程序,您的网格必须看起来像 - .container/.container-fluid > .row > .col-Look at the documentation for grid system for more info
    • 查看文档并遵循.container-fluid &gt; .row &gt; .col-xs-12 的结构,但显示的结果相同:/
    • 是的,我的错 - .col- 元素还添加了一些填充。它应该仅使用 .container-fluid > .row 工作。 Check the bootply.
    • 或者另一种方法是删除 container-fluid 填充 - bootply
    【解决方案2】:

    第一件事:你必须放一个重置css链接(它必须是第一个)。你可以在这里找到一个:http://meyerweb.com/eric/tools/css/reset/ 然后如果你想让容器匹配一个 div 元素的总宽度,它必须是一个容器流体

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多