在bootstrap documentation他们能够在他们的 .bs-docs-example
div 中“捕获”一个 .navbar-fixed-top
:
<div class="bs-docs-example bs-navbar-top-example">
<div class="navbar navbar-fixed-top" style="position: absolute;">
<div class="navbar-inner">
[...]
但是如果我在我的测试页面中做同样的事情,导航栏会“转义”div 并固定在主体的顶部,而不是 div 的顶部。技巧是如何实现的?
最佳答案
好的,明白了。父元素容器必须有 position: relative
,而 navbar 必须有 position: absolute
,如果你附加 .navbar-fixed-top
或 .navbar-fixed-bottom
它将相对于父元素而不是相对于整个页面固定。是啊!
关于javascript - Bootstrap 将导航栏固定在 div 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14742906/