bootstrap 4使下拉列表可滚动

时间:2017-12-05 03:31:47

标签: html css twitter-bootstrap css3

我的小型设备上的下拉菜单有问题。当我在这里尝试解决方案时,我无法使其滚动(即 溢出:自动/溢出-y:滚动 )即使我使用它也无法正常工作 !重要。即使下拉菜单打开,我能够滚动的内容也是我的主页面。 enter image description here

<nav class="navbar navbar-toggleable-sm ">
    <button class="navbar-toggler navbar-toggler-right main-navbar-toggler" type="button" data-toggle="collapse" data-target="#main-nav-collapse" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
        <span class="fa fa-bars"></span>
    </button>
    <a class="navbar-brand animation" data-animation ="fadeInLeft" href="#"><img src="/093017/img/logo-tmi.png" alt="logo"/></a>
    <div class="collapse navbar-collapse" id = "main-nav-collapse" >
        <ul class="nav navbar-nav navbar-main mr-auto mt-2 mt-md-0 animation" data-animation = "fadeInRight">
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Vehicles</a>
                <div class="dropdown-menu default-menu main-menu sm-main-menu animation" data-animation = "fadeIn">
                    <!-- Nav tabs -->
                    <div class="sm-main-nav" >
                        <a class="dropdown-item" href="#">Cars</a><hr>
                        <a class="dropdown-item" href="#">Vans & Pickup</a><hr>
                        <a class="dropdown-item" href="#">SUVs & Crossover</a><hr>
                        <a class="dropdown-item" href="#">MPVs</a><hr>
                        <a class="dropdown-item" href="#">Hybrid</a><hr>
                        <a class="dropdown-item" href="#">Performance</a>
                    </div>
                </div>
            </li>
            <li class="nav-item">
                <a class="nav-link " href="#">Owners</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Shop</a>
            </li>
            <li class="nav-item">
                <a class="nav-link " href="#">Promotions</a>
            </li>
        </ul>
    </div>

4 个答案:

答案 0 :(得分:11)

你可以在你的css中使用@media

InputStream

答案 1 :(得分:3)

使用最大高度而不是高度:

.dropdown-menu {         
  max-height: 200px;
  overflow-y: auto;
}

答案 2 :(得分:2)

我可以建议代替以像素为单位的硬编码高度,您可以利用视口高度,例如将这种样式添加到下拉菜单项中或在类级别添加

内联

style="overflow-y:auto; max-height:80vh"

对于每个下拉列表

.dropdown-menu {
 overflow-y:auto; 
 max-height:80vh
}

答案 3 :(得分:1)

您可以将滚动条的自定义类用于下拉列表。

<div class="sm-main-nav customClassForDropDown" >
                        <a class="dropdown-item" href="#">Cars</a><hr>
                        <a class="dropdown-item" href="#">Vans & Pickup</a><hr>
                        <a class="dropdown-item" href="#">SUVs & Crossover</a><hr>
                        <a class="dropdown-item" href="#">MPVs</a><hr>
                        <a class="dropdown-item" href="#">Hybrid</a><hr>
                        <a class="dropdown-item" href="#">Performance</a>
</div>

这是自定义css类。

 .customClassForDropDown
    {
       height: 100px;
       overflow-y: auto;
    }

检查此JSFIDDLE