twitter-bootstrap-3 – 如何使用带有可折叠菜单的bootstrap scrollspy?

前端之家收集整理的这篇文章主要介绍了twitter-bootstrap-3 – 如何使用带有可折叠菜单的bootstrap scrollspy?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个MCQ问题网站.在考试中,可能有来自不同科目的100-200个问题.所以我想让导航变得更容易.由于导航非常大,所以我想在开放主题下打开问题,即:当主题1处于活动状态时,只有主题1下的问题链接可见,如Bootstrap网站的右侧导航.我的工作样本如下.

I used Bootstrap scrollspy according to their site instruction and it
worked fine. But when I try to make it collapsible (like Bootstrap
website’s right navigation)
it does not work.

我正在使用Bootstrap – 3.3.2

<body data-spy="scroll" data-target="#subjectNavbar" data-offset="0">
    <header id="header" class="container-fluid navbar-fixed-top">
        ...
    </header>
    <div class="container">
        <div class="row">
            <aside id="left-column" class="col-sm-3">
                <nav id="subjectNavbar" class="sub-nav">
                    <ul class="nav subject-ul">
                        <li>
                            <a href="#subject-1">Subject 1</a>
                            <ul class="list-inline question-ul">
                                <li id="question-no-1"><a href="#question-1">1</a></li> 
                                <li id="question-no-2"><a href="#question-2">2</a></li> 
                                <li id="question-no-3"><a href="#question-3">3</a></li> 
                                ...
                                <li id="question-no-20"><a href="#question-20">20</a></li> 
                            </ul>
                        </li>
                        <li>
                            <a href="#subject-2">Subject 2</a>
                            <ul class="list-inline question-ul">
                                <li id="question-no-21"><a href="#question-21">21</a></li> 
                                <li id="question-no-22"><a href="#question-22">22</a></li> 
                                <li id="question-no-23"><a href="#question-23">23</a></li> 
                                ...
                                <li id="question-no-40"><a href="#question-40">40</a></li> 
                            </ul>
                        </li>
                        ...
                        <li>
                            <a href="#subject-5">Subject 5</a>
                            <ul class="list-inline question-ul">
                                <li id="question-no-81"><a href="#question-81">81</a></li> 
                                <li id="question-no-82"><a href="#question-82">82</a></li> 
                                <li id="question-no-83"><a href="#question-83">83</a></li> 
                                ... 
                                <li id="question-no-100"><a href="#question-100">100</a></li>
                            </ul>
                        </li>
                    </ul>
                </nav>                
            </aside>
            <section class="col-sm-6">
                <div class="question-paper">
                    <div class="subject-group" id="subject-1">
                        <h2>Subject 1</h2>
                        <article id="question-1">
                            <header><em>1.</em> Question 1</header>
                            <ol>
                                <li>Option A</li>
                                <li>Option B</li>
                                <li>Option C</li>
                                <li>Option D</li>
                            </ol>
                        </article>
                        ...
                        <article id="question-20">
                            <header><em>20.</em> Question 20</header>
                            <ol>
                                <li>Option A</li>
                                <li>Option B</li>
                                <li>Option C</li>
                                <li>Option D</li>
                            </ol>
                        </article>
                    </div> 
                    ...
                    <div class="subject-group" id="subject-5">
                        <h2>Subject 5</h2>
                        <article id="question-81">
                            <header><em>81.</em> Question 81</header>
                            <ol>
                                <li>Option A</li>
                                <li>Option B</li>
                                <li>Option C</li>
                                <li>Option D</li>
                            </ol>
                        </article>
                        ...
                        <article id="question-100">
                            <header><em>100.</em> Question 100</header>
                            <ol>
                                <li>Option A</li>
                                <li>Option B</li>
                                <li>Option C</li>
                                <li>Option D</li>
                            </ol>
                        </article>
                    </div> 
                </div>
            </section>
            <aside id="right-column" class="col-sm-3">
                ...
            </aside>
        </div><!--/row-->
    </div><!--/.container-->
    <footer class="container">
        ...
    </footer>
</body>

解决方法

在对bootstrap网站本地css和javascript文件进行深入研究后,我发现他们使用css使导航可折叠.他们将ul设置为活动可见,而其他子设备显示无.
.subject-ul .question-ul{
    display:none;
}

.subject-ul li.active>.question-ul{
    display:visible;
}

猜你在找的Bootstrap相关文章