Multilevel Dropdown in Bootstrap 3.3.5

前端 未结 1 463
情深已故
情深已故 2021-02-06 10:08

I have the following HTML code and I\'ve structured it to how I think it should be achieved based on the mark-up in the Bootstrap docs.

相关标签:
1条回答
  • 2021-02-06 10:28

    I don't recall any default example from bootstrap 3 having 3 level drop down nav menu, but you can do like this, little bit of customization and java-script and it's fully responsive.

    HTML

    <div id="navbar" class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
            <li class="active"> <a href="#">Home</a>
            </li>
            <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Hospital<b class="caret"></b></a>
                <ul class="dropdown-menu">
                    <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Consultants</a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Adult cardiac surgery</a>
                            </li>
                            <li><a href="#">Bariatric surgery</a>
                            </li>
                            <li><a href="#">Colorectal surgery</a>
                            </li>
                            <li><a href="#">Endocrine and thyroid surgery</a>
                            </li>
                            <li><a href="#">Head and neck cancer surgery</a>
                            </li>
                            <li><a href="#">Interventional cardiology</a>
                            </li>
                            <li><a href="#">Lung Cancer</a>
                            </li>
                            <li><a href="#">Neurosurgery</a>
                            </li>
                            <li><a href="#">Orthopaedic surgery</a>
                            </li>
                            <li><a href="#">Upper gastro-intestinal surgery</a>
                            </li>
                            <li><a href="#">Urological surgery</a>
                            </li>
                            <li><a href="#">Vascular surgery</a>
                            </li>
                        </ul>
                    </li>
                    <li><a href="#">Another action</a>
                    </li>
                    <li><a href="#">Something else here</a>
                    </li>
                    <li role="separator" class="divider"></li>
                    <li class="dropdown-header">Nav header</li>
                    <li><a href="#">Separated link</a>
                    </li>
                    <li><a href="#">One more separated link</a>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
    

    CSS

    .dropdown-submenu {
        position:relative;
    }
    .dropdown-submenu>.dropdown-menu {
        top:0;
        left:100%;
        margin-top:-6px;
        margin-left:-1px;
        -webkit-border-radius:0 6px 6px 6px;
        -moz-border-radius:0 6px 6px 6px;
        border-radius:0 6px 6px 6px;
    }
    .dropdown-submenu>a:after {
        display:block;
        content:" ";
        float:right;
        width:0;
        height:0;
        border-color:transparent;
        border-style:solid;
        border-width:5px 0 5px 5px;
        border-left-color:#cccccc;
        margin-top:5px;
        margin-right:-10px;
    }
    .dropdown-submenu:hover>a:after {
        border-left-color:#555;
    }
    .dropdown-submenu.pull-left {
        float:none;
    }
    .dropdown-submenu.pull-left>.dropdown-menu {
        left:-100%;
        margin-left:10px;
        -webkit-border-radius:6px 0 6px 6px;
        -moz-border-radius:6px 0 6px 6px;
        border-radius:6px 0 6px 6px;
    }
    

    JS

    (function ($) {
        $(document).ready(function () {
            $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function (event) {
                event.preventDefault();
                event.stopPropagation();
                $(this).parent().siblings().removeClass('open');
                $(this).parent().toggleClass('open');
            });
        });
    })(jQuery);
    

    Working Example

    0 讨论(0)
提交回复
热议问题