Bootstrap下拉子菜单丢失

本文翻译自:Bootstrap dropdown sub menu missing

Bootstrap 3 is still at RC, but I was just trying to implement it. Bootstrap 3仍在RC中,但是我只是在尝试实现它。 I couldn't figure out how to put a sub menu class. 我不知道如何放置一个子菜单类。 Even there is no class in css and even the new docs don't say anything about it 甚至CSS中没有类,甚至新文档也没有说什么

It was there in 2.x with class name as dropdown-submenu 它在2.x中存在,类名称为dropdown-submenu


#1楼

参考:https://stackoom.com/question/1DcjV/Bootstrap下拉子菜单丢失


#2楼

Updated 2018 更新于2018

The dropdown-submenu has been removed in Bootstrap 3 RC. dropdown-submenu已在Bootstrap 3 RC中删除。 In the words of Bootstrap author Mark Otto.. 用Bootstrap作者Mark Otto的话来说。

"Submenus just don't have much of a place on the web right now, especially the mobile web. They will be removed with 3.0" - https://github.com/twbs/bootstrap/pull/6342 “子菜单现在在网络上没有什么位置,特别是在移动网络上。它们将在3.0中删除。” -https://github.com/twbs/bootstrap/pull/6342

But, with a little extra CSS you can get the same functionality. 但是,仅需一点额外的CSS,您就能获得相同的功能。

Bootstrap 4 (navbar submenu on hover) Bootstrap 4 (悬停时的导航栏子菜单)

.navbar-nav li:hover > ul.dropdown-menu {
    display: block;
}
.dropdown-submenu {
    position:relative;
}
.dropdown-submenu>.dropdown-menu {
    top:0;
    left:100%;
    margin-top:-6px;
}

Navbar submenu dropdown hover 导航栏子菜单下拉悬停
Navbar submenu dropdown hover (right aligned) 导航栏子菜单下拉悬停(右对齐)
Navbar submenu dropdown click (right aligned) 导航栏子菜单下拉单击(右对齐)
Navbar dropdown hover (no submenu) 导航栏下拉悬停(无子菜单)


Bootstrap 3 引导程序3

Here is an example that uses 3.0 RC 1: http://bootply.com/71520 这是使用3.0 RC 1的示例: http : //bootply.com/71520

Here is an example that uses Bootstrap 3.0.0 (final): http://bootply.com/86684 这是使用Bootstrap 3.0.0(最终版)的示例: http : //bootply.com/86684

CSS 的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:hover>.dropdown-menu {
    display:block;
}
.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:#ffffff;
}
.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;
}

Sample Markup 样本标记

<div class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">  
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="collapse navbar-collapse navbar-ex1-collapse">
            <ul class="nav navbar-nav">
                <li class="menu-item dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Drop Down<b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li class="menu-item dropdown dropdown-submenu">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Level 1</a>
                            <ul class="dropdown-menu">
                                <li class="menu-item ">
                                    <a href="#">Link 1</a>
                                </li>
                                <li class="menu-item dropdown dropdown-submenu">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Level 2</a>
                                    <ul class="dropdown-menu">
                                        <li>
                                            <a href="#">Link 3</a>
                                        </li>
                                    </ul>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</div>

PS - Example in navbar that adjusts left position: http://bootply.com/92442 PS-导航栏上的示例可调整左侧位置: http//bootply.com/92442


#3楼

@skelly solution is good but will not work on mobile devices as the hover state won't work. @skelly解决方案很好,但由于悬停状态不起作用,因此不适用于移动设备。

I have added a little bit of JS to get the BS 2.3.2 behavior back. 我添加了一些JS来恢复BS 2.3.2的行为。

PS: it will work with the CSS you get there: http://bootply.com/71520 though you can comment the following part: PS:它将与您到达的CSS一起使用: http//bootply.com/71520,尽管您可以评论以下部分:

CSS: CSS:

/*.dropdown-submenu:hover>.dropdown-menu{display:block;}*/

JS: JS:

$('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
  // Avoid following the href location when clicking
  event.preventDefault();
  // Avoid having the menu to close when clicking
  event.stopPropagation();
  // If a menu is already open we close it
  $('ul.dropdown-menu [data-toggle=dropdown]').parent().removeClass('open');
  // opening the one you clicked on
  $(this).parent().addClass('open');
});

The result can be found on my WordPress theme (Top of the page): http://shprinkone.julienrenaux.fr/ 结果可以在我的WordPress主题(页面顶部)上找到: http : //shprinkone.julienrenaux.fr/


#4楼

Shprink's code helped me the most, but to avoid the dropdown to go off-screen i updated it to: Shprink的代码对我的帮助最大,但是为了避免出现下拉菜单,我将其更新为:

JS: JS:

$('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
    // Avoid following the href location when clicking
    event.preventDefault(); 
    // Avoid having the menu to close when clicking
    event.stopPropagation(); 
    // If a menu is already open we close it
    $('ul.dropdown-menu [data-toggle=dropdown]').parent().removeClass('open');
    // opening the one you clicked on
    $(this).parent().addClass('open');

    var menu = $(this).parent().find("ul");
    var menupos = $(menu).offset();

    if (menupos.left + menu.width() > $(window).width()) {
        var newpos = -$(menu).width();
        menu.css({ left: newpos });    
    } else {
        var newpos = $(this).parent().width();
        menu.css({ left: newpos });
    }

});

CSS: FROM background-color: #eeeeee TO background-color: #c5c5c5 - white font & light background wasn't looking good. CSS:从background-color:#eeeeee到background-color:#c5c5c5-白色字体和浅色背景看起来不太好。

.nav .open > a,
.nav .open > a:hover,
.nav .open > a:focus {
  background-color: #c5c5c5;
  border-color: #428bca;
}

I hope this helps people as much as it did for me! 我希望这能对我有所帮助!

But i hope Bootstrap add the subs feature back ASAP. 但我希望Bootstrap尽快添加潜艇功能。


#5楼

Until today (9 jan 2014) the Bootstrap 3 still not support sub menu dropdown. 直到今天(2014年1月9日),Bootstrap 3仍不支持子菜单下拉菜单。

I searched Google about responsive navigation menu and found this is the best i though. 我在Google上搜索了响应式导航菜单,发现这是我最好的菜单。

It is Smart menus http://www.smartmenus.org/ 这是智能菜单 http://www.smartmenus.org/

I hope this is the way out for anyone who want navigation menu with multilevel sub menu. 我希望这是任何想要带有多层子菜单的导航菜单的人的出路。

update 2015-02-17 Smart menus are now fully support Bootstrap element style for submenu. 更新2015-02-17智能菜单现已完全支持子菜单的Bootstrap元素样式。 For more information please look at Smart menus website. 有关更多信息,请访问Smart menus网站。


#6楼

I make another solution for dropdown. 我为下拉菜单提出了另一种解决方案。 Hope this is helpfull Just add this js script 希望对您有所帮助。只需添加此js脚本

<script type="text/javascript"> jQuery("document").ready(function() {
  jQuery("ul.dropdown-menu > .dropdown.parent").click(function(e) {
    e.preventDefault();
    e.stopPropagation();
    if (jQuery(this).hasClass('open2'))
      jQuery(this).removeClass('open2');
    else {
      jQuery(this).addClass('open2');
    }

  });
}); < /script>

<style type="text/css">.open2{display:block; position:relative;}</style>
1.1网站开发背景 2006年上半年,我国餐饮市场消费需求较旺,景气指数明显攀升,营业额继续保持较强的增长势头。据国家统计局统计,上半年餐饮业实现营业额3373.7亿元,与去年同期增长24.5%:其中一季度实现营业额1742.3亿元,同比增长16.6%;二季度餐饮业实现营业额1631.4亿元,同比增长达到34.2%,增幅较大,主要是去年同期餐饮业受非典影响增幅下降10.1个百分点,同比基数较低的因素影响。据推算,我国现有餐饮网点达到400万个,其中个体私营企业380万个,占到95%左右;外资合资与国有企业约20万个,占到5%左右,企业结构不断调整,行业规模继续扩大。近两年来,一大批网站正在吸引着人们的眼球。然而,除了少数网站受到风险投资的青睐并实现飞跃式发展之外,很大一部分正处于迷茫摸索甚至挣扎的状态。在餐饮业这样一个与老百姓“衣食住行”息息相关的传统领域,各种网站走出了不同电商务之路,催生出餐饮业电商务发展。 随着生活质量的提高,对饮食消费理性化、经营特色化和市场细分化的特点日益突现出来。调查反映,2006年上半年的餐饮消费在需求能力有所提高的同时,顾客的就餐选择性和多样性的特点明显,更加追求企业的品牌特色、营养健康和环境服务的综合水平,特别是对餐饮企业的经营特色化和差异性的要求不断提高,特色餐饮对消费的吸引力明显增强。餐饮企业的创新能力不断提升,在经营业态、菜品推出、风味设计和文化氛围等方面加大开发力度,市场细分化趋势增强,更加丰富多彩。随着饮食市场的不断变化对业界提出了一系列新的要求,而通过电商务网站形式加强企业的竞争能力已经成为一种趋势,所以我建立了一个美食网站。本文主要针对该网站的各方面内容进行描述。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值