如何让Bootstrap下拉子菜单"dropup"

use*_*864 48 html css twitter-bootstrap drop-down-menu

我有一个Bootstrap下拉菜单.最后li一项是子菜单.当完整菜单下降时,如何让子菜单丢弃?这是代码:

<div class="dropdown">
    <a class="inputBarA dropdown-toggle" data-toggle="dropdown" href="#">FILTER</a>
    <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
        <li role="presentation">
            <a role="menuitem" href="#">Text</a>
        </li>
        <li role="presentation">
            <label>Label name</label>
            <label>Label name</label>
            <label class="checkbox">
                <input type="checkbox">
                Text </label>
            <label class="checkbox">
                <input type="checkbox">
                Text </label>
            <label class="checkbox">
                <input type="checkbox">
                Text </label>
            <label class="checkbox">
                <input type="checkbox">
                Text </label>
        </li>
        <li class="dropdown-submenu">
            <a tabindex="-1" href="#">Centralities</a>
            <ul class="dropdown-menu">
                <label class="radio">
                    <input type="radio" name="options" id="optionsRadios1" value="A" checked>
                    AA </label>
                <label class="radio">
                    <input type="radio" name="options" id="optionsRadios2" value="B">
                    BB </label><label class="radio">
                    <input type="radio" name="options" id="optionsRadios2" value="C">
                    CC </label><label class="radio">
                    <input type="radio" name="options" id="optionsRadios2" value="D">
                    DD </label><label class="radio">
                    <input type="radio" name="options" id="optionsRadios2" value="E">
                    EE </label>
            </ul>
        </li>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

Sem*_*Sem 57

最好的解决方案:

<div class="dropup">
   <ul class="dropdown-menu"></ul>
</div>
Run Code Online (Sandbox Code Playgroud)

它是bootstrap中的本机类.引导程序(使用3.1.1)css文件有一个.dropup .dropdown-menu选择器,这就是我发现的方式.


DrC*_*ord 52

听起来下面的答案将是如何从头开始,我不知道Bootstrap中有一个dropup类...

所以简短的Bootstrap答案是将类"dropup"应用于<ul>早期版本的bootstrap中:

 <ul class="dropdown-menu dropup" role="menu" aria-labelledby="dLabel">
Run Code Online (Sandbox Code Playgroud)

但是在较新版本的bootstrap(v3)中,"dropup"类需要应用于<ul>容器而不是<ul>自身:

<div class="dropup">
    <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
</div>
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/ZgyZP/5/

不使用bootstrap的原始工作答案:

您可以使用javascript计算子菜单的高度,然后负向偏移子菜单的位置.

像(使用jQuery):

$('.dropdown-submenu').hover(
    function(){
    //hover in 
        $('.dropdown-submenu > ul').css('top', '-' + $('.dropdown-submenu > ul').css('height'));

    },
    //hover out
    function(){
    }
);
Run Code Online (Sandbox Code Playgroud)

小提琴:http://jsfiddle.net/ZgyZP/4/

  • 这是不正确的,“dropup”类位于容器上,即“&lt;ul&gt;”的父级,而不是“&lt;ul&gt;”本身。引导程序 3.3.2。 (2认同)
  • @leftclickben - 感谢您提醒我更新:D (2认同)

Man*_*h V 23

使用一类,喜欢 <ul class="dropdown up">

写风格 .up { bottom:100% !important; top:auto !important; }

注意: 根据按钮大小增加底部.

  • greeeeeeeat解决方案! (3认同)
  • 这对我有用."dropup"课程没有用,让我的菜单看不见.也许是因为我的菜单以某种奇怪的方式嵌套了. (2认同)