Bootstrap 内容无法与固定宽度的侧边栏一起正确布局

Bootstrap content doesn't lay out correctly in conjunction with fixed width sidebars

列的第一行和第二行之间有很大的白色间隙。

JSFiddle:https://jsfiddle.net/5o3ug26g/

<!DOCTYPE html>
<html>
<head>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .content {
            margin-left: 170px;
            margin-right: 170px;
        }

        .sidebar { width: 160px; height: 600px; }
        .left { float: left; background: forestgreen; }
        .right { float: right; background: steelblue; }
    </style>
</head>


<body>
    <div>
        <div class="left sidebar"></div>

        <div class="right sidebar"></div>

        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-6">Text on top of the page</div>
                    <div class="col-md-6">Other text on top of the page</div>
                </div>

                <div class="row">
                    <div class="col-md-6">I want this to be right below the "Text on top of the page" but it isn't...</div>
                    <div class="col-md-6">... and I want this to be right below the "Other text on top of the page" but it isn't</div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

如果我删除 row 类 那么间隙就会消失,但是当使用 Bootstrap navbar-s 和其他带有 [=14 的容器时也会出现这个问题=],因此仅删除 row 类 不是解决方案。

我尝试在很多地方添加 clearfix 但无济于事。

这是一个更复杂的响应式布局的摘录,我宁愿避免重构它。

最简单的修复方法是什么?

您可以绝对定位左右边栏,而不是浮动它们。浮动干扰了 bootstrap 布局。

.left { background: forestgreen; position:absolute; left:0; top:0; }
.right { background: steelblue; position:absolute; right:0; top:0;}

从你的分叉出来的实例:https://jsfiddle.net/5fk5900s/1/

马塞洛是正确的。您已经为内容添加了边距以说明侧边栏。这是一个 fiddle 的绝对定位变化:

https://jsfiddle.net/5o3ug26g/1/

.content {
    margin-left: 170px;
    margin-right: 170px;
}

.sidebar { 
    position: absolute;
    width: 160px; 
    height: 600px; 
}
.left { 
    left: 0px; 
    background: 
    forestgreen; 
}
.right { 
    right: 0px; 
    background: steelblue; 
}