在 Twitter Bootstrap 中折叠时隐藏下拉菜单的子项
我的导航栏中有一个下拉菜单,但它有很多子项目。这在较大的屏幕上很好,但是当导航折叠时,它们并没有真正重要到占据它们所占用的所有空间。
有什么方法可以在折叠时关闭下拉菜单,或者删除下拉菜单和子项目并将其替换为锚标记(它将转到用户可以选择子项目的页面)?还是我的想法全错了?
<!-- Navbar -->
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<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">
<ul class="nav">
<li<{if $contenttemplate == "option1"}> class="active" <{/if}>><a href="/">option1</a></li>
<li<{if $contenttemplate == "option2"}> class="active" <{/if}>><a href="/option2">option2</a></li>
<li<{if $contenttemplate == "option3"}> class="active" <{/if}>><a href="/option3">option3</a></li>
<li<{if $contenttemplate == "dropdown"}> class="dropdown active" style="background-color:rgba(0,0,0,0.5);"
<{else}> class="dropdown"<{/if}>>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">lists<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/lists/number1">number1</a></li>
<li><a href="/lists/number2">number2</a></li>
<li><a href="/lists/number3">number3</a></li>
<li><a href="/lists/number4">number4</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
I have a drop down menu in my nav bar but it has quite a few sub-items. This is fine on a larger screen, but when the nav is collapsed they're not really important enough to take up all the room that they do.
Is there any way to close the dropdown when it is collapsed, or to remove the dropdown and subitems and replace it with an anchor tag (where it'll go to a page where the user can select the subitem)? Or am I thinking about this all wrong?
<!-- Navbar -->
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<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">
<ul class="nav">
<li<{if $contenttemplate == "option1"}> class="active" <{/if}>><a href="/">option1</a></li>
<li<{if $contenttemplate == "option2"}> class="active" <{/if}>><a href="/option2">option2</a></li>
<li<{if $contenttemplate == "option3"}> class="active" <{/if}>><a href="/option3">option3</a></li>
<li<{if $contenttemplate == "dropdown"}> class="dropdown active" style="background-color:rgba(0,0,0,0.5);"
<{else}> class="dropdown"<{/if}>>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">lists<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/lists/number1">number1</a></li>
<li><a href="/lists/number2">number2</a></li>
<li><a href="/lists/number3">number3</a></li>
<li><a href="/lists/number4">number4</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Twitter Bootstrap 中有预定义的类用于响应式渲染。您可以使用
仅在您提到的较大屏幕上显示。其他可用的类有 .visible-phone、.visible-tablet、.hidden-phone、.hidden-tablet、.hidden-desktop。
There are predefined classes in twitter bootstrap for responsive rendering. You can use
<a class="dropdown-toggle visible-desktop" .../>
to be displayed only for larger screens as you mentioned. The other classes available are .visible-phone, .visible-tablet, .hidden-phone, .hidden-tablet, .hidden-desktop.