Bootstrap ~ Implementation of multi-level navigation (cascade navigation) and bootstrap navigation

Source: Internet
Author: User

Bootstrap ~ Implementation of multi-level navigation (cascade navigation) and bootstrap navigation

Back to directory

On the bootstrap official website, navigation is at most two levels, which cannot be achieved at two or more levels. Uncle found some third-party information and finally found a good plug-in. Both the Use and effect are good, now, let's share it with you.

Plug-in address: http://vsn4ik.github.io/bootstrap-submenu/

Let's take a look at the display effect on Uncle's background system.

The implementation method is as follows:

1. Reference three JS plug-ins and a CSS class library

    <script src="~/Content/bootstraps/JS/bootstrap-submenu.js"></script>    <script src="~/Content/bootstraps/JS/highlight.min.js"></script>    <script src="~/Content/bootstraps/JS/docs.js"></script>    <link href="~/Content/bootstraps/CSS/bootstrap-submenu.css" rel="stylesheet" />

2. Insert the corresponding HTML code block. In this example, the code is not generated recursively, and the static three-level structure is used. This makes it clearer. We recommend that you use recursion to produce menus in a real production environment.

<ul class="nav nav-pills">    @foreach (var item in Model)    {        if (item.Sons != null && item.Sons.Count > 0)        {                        <li class="dropdown">            <a data-submenu="" data-toggle="dropdown" tabindex="0">@item.MenuName<span class="caret"></span></a>            <ul class="dropdown-menu">                @foreach (var sub in item.Sons)                {                    if (sub.Sons != null && item.Sons.Count > 0)                    {                    <li class="dropdown-submenu">                        <a tabindex="0">@sub.MenuName</a>                        <ul class="dropdown-menu">                            @foreach (var inner in sub.Sons)                            {                                <li>                                    <a href="@inner.LinkUrl">@inner.MenuName</a>                                </li>                            }                        </ul>                    </li>                    <li class="divider"></li>                    }                    else                    {                    <li><a href="@sub.LinkUrl">@sub.MenuName</a></li>                    }                }            </ul>        </li>        }        else        {        <li><a href="@item.LinkUrl">@item.MenuName</a></li>        }    }</ul>

The final result is the first figure. It is worth noting that you can add <li class = "divider"> </li> this line of code if you want to use a split line between menus.

Thank you for reading this article!

 

Back to directory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.