修复了bootstrap中的div

时间:2016-07-07 12:41:22

标签: css twitter-bootstrap twitter-bootstrap-3

<div class="container-fluid yellow">
    <div class="container blue">
        <div class="red"></div>
    </div>
</div>

CSS

.yellow {
    height: 160px; 
    background: yellow;
}
.blue { 
    height: 160px; 
    background: blue; 
    color: #fff;
    position: relative;
}
.red { 
    height: 160px; 
    background: red; 
    position: fixed;
}

我是UI&amp;自举。

对于&#34;容器&#34; (蓝色)我给了position: relative

当我将position: fixed提交给div&#39;红色&#39;时,它会移到一边而不是留在原位。

如何解决?

2 个答案:

答案 0 :(得分:0)

Bootstrap的主要优点是能够为您创建响应式网站的div。一般情况下,您不会设置CSS位置属性,而是让Bootstrap为您执行此操作以便以理智的方式传递div。

如果您想玩和了解CSS位置属性,最好不要在引导配置中进行。

答案 1 :(得分:0)

如果您将div设为红色,fixed,那么您需要定义该div的width。例如,将其添加到您的代码中:

.red {
    width: 100px;
}

以下是JSBin示例。如果您需要更多信息,请告诉我。