在 Twitter Bootstrap 中折叠时隐藏下拉菜单的子项

发布于 2025-01-07 16:07:27 字数 2092 浏览 1 评论 0原文

我的导航栏中有一个下拉菜单,但它有很多子项目。这在较大的屏幕上很好,但是当导航折叠时,它们并没有真正重要到占据它们所占用的所有空间。

有什么方法可以在折叠时关闭下拉菜单,或者删除下拉菜单和子项目并将其替换为锚标记(它将转到用户可以选择子项目的页面)?还是我的想法全错了?

<!-- 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落日海湾 2025-01-14 16:07:27

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文