3

我有一些 html 用于我的研究小组制作的软件库站点的页面布局。这是通过引导程序 3 完成的。我想要实现的是出现在 jumbotron 下方的导航栏,一旦向上滚动,就会固定在页面顶部。我还希望页面左列中的 nag 元素具有类似的行为 - 当页面滚动并且它们到达顶部时 - 然后它们变得固定并留在那里。从阅读中我了解到 twitter bootstrap 中的 Affix 是这样做的方法,但我不完全确定我能弄清楚如何正确地做到这一点。

使用下面的 HTML,滚动到目前为止,应该跨越页面的导航栏被压扁 - 导航栏链接移动到导航栏品牌下方的一行,并且栏不再跨越页面。一旦我弄清楚如何将词缀与导航栏一起使用,我希望将它与导航元素一起使用。谁能解释我需要做什么才能获得效果?我对网页设计的东西相当陌生。

谢谢,本。

HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>SOFTWARE - GETTING STARTED WITH SOFTWARE</title> 
        <link rel="stylesheet" href="css/bootstrap.css" type="text/css"/>
    </head>
    <body>
        <style>
            .jumbotron {
                margin-bottom: 0px;
            }
        </style>
        <!-- Start of main container -->
        <div class="container-fluid main">
            <div class="row-fluid">
                <div class="jumbotron">
                    <h1> Getting Started </h1>
                    <p> Installing SOFTWARE on your machine is easy for most systems.
                        This guide will get you up and running.
                    </p>
                </div>
            </div>
                    <!--Here's thestart of the navabar I'm trying to affix -->
            <div class="row-fluid" data-spy="affix" data-offset-top="200">
                <div class="navbar navbar-inverse">
                    <div class="navbar-header">
                        <a class="navbar-toggle" 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="navbar-brand" href="#">SOFTWARE</a>
                    </div>
                    <div class="navbar-collapse collapse">
                        <ul class="nav navbar-nav">
                            <li><a href="#">Home</a></li>
                            <li><a href="#">About SOFTWARE</a></li>
                            <li class="active"><a href="#">Getting Started</a></li>
                            <li><a href="#">Quick Start</a></li>
                            <li><a href="#">Full Documentation</a></li>
                            <li><a href="#">Contact</a></li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Download <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    <li><a href="#">GitHub Repository</a></li>
                                    <li><a href="#">Download TAR</a></li>
                                    <li><a href="#">Download ZIP</a></li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>  
            </div>
            <!-- Begin Layout for Getting Started Page -->
            <div class="row-fluid">
                <div class="col-lg-3">
                    <ul class="nav nav-pills nav-stacked sidemenu">
                        <li><a href="#">Introduction</a></li>
                        <li><a href="#">Installing R</a></li>
                        <li><a href="#">R Recommendations</a></li>
                        <li><a href="#">Installing HybRIDS from GitHub</a></li>
                        <li><a href="#">Installing HybRIDS from Source File</a></li>
                        <li><a href="#">Installing HybRIDS from Binary File</a></li>
                    </ul>
                </div>
                <div class="col-lg-9 whitep">
                    <h1 class="whitep">Introduction</h1>
                    <p>
                        Installation text
                        Installation text
                        Installation text
                        Installation text
                        Installation text
                    </p>
                    <hr>
                    <h1>Installing R</h1>
                    <p>
                        R is simple to install for most operating systems. If you use a Mac or PC or Linux system, the process for installing it is like for installing any other software on that system. 
                    </p>
                    <p>
                    TEST text to fill page to test scrolling behaviour...
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>
                    <p>
                    TEST
                    </p>    
                </div>
            </div>
        </div> <!--End of main Container-->
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script src="js/bootstrap.js"></script>
    </body>
</html>
4

1 回答 1

8

如 Bootstrap 文档中所述,您必须为 nav 和 navbar 定义 CSS 类,以便在affix启动时...

“你必须自己提供这些类的样式(独立于这个插件)。affix-top 类应该在文档的常规流中。”

所以你需要为顶部导航栏和侧边导航设置一些 CSS ..

#nav.affix {
    position: fixed;
    top: 0;
    width: 100%;
    z-index:10;
}

#sidebar.affix {
    position: fixed;
    top: 80px;
}

affix这是一个同时使用顶部和侧面导航的 Bootply 演示: http ://bootply.com/69848

于 2013-08-26T20:23:00.067 回答