小编Max*_*ray的帖子

Bootstrap:锚和身体上边距/填充

我正在使用Bootstrap,其全局导航栏固定在页面主体的顶部.

    <div class="navbar navbar-fixed-top navbar-inverse">
        <div class="navbar-inner">
            <div class="container">
                <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </a>
                <a class="brand" href="/">MyBrand</a>
                <div class="nav-collapse collapse">
                    <ul class="nav">
                        <li><a href="#>Page 1</li>
                        <li><a href="#>Page 2</li>
                        <li><a href="#>Page 3</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

我在主体顶部添加了40px的边距,以使页面内容的顶部不会被导航栏覆盖.

body {
    background-color: #f5f5f5;
    position: relative;
    margin-top: 40px;
}
Run Code Online (Sandbox Code Playgroud)

到那里,一切正常.我还使用内部锚点来简化页面内部的导航,使用Twitter与Bootstrap文档中的词缀组件一起使用的相同机制,使用户能够跳转到页面中的不同部分(请参阅http:// twitter.github.com/bootstrap/getting-started.html)

<a href="#section1">Section 1</a>
<a href="#section2">Section 2</a>
<a href="#section3">Section 3</a>

[...]

<section id="section1">
    [...]
    [...]
    [...]
</section
<section id="section2">
    [...]
    [...]
    [...]
</section
<section …
Run Code Online (Sandbox Code Playgroud)

anchor margin navbar twitter-bootstrap

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

anchor ×1

margin ×1

navbar ×1

twitter-bootstrap ×1