jmv
jmv

Reputation: 415

bootstrap 4 making dropdown scrollable

I have a problem with my drop down menu on smaller devices. i cannot make it scroll able when i tried the solution here (that is overflow:auto/ overflow-y:scroll) it's not working even if i use !important. What i'm able to scroll was my main page even if the drop down is open. 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>

Upvotes: 15

Views: 44147

Answers (4)

Udhay Titus
Udhay Titus

Reputation: 5869

just you can use @media in your css

@media (max-width: 500px) {
    .dropdown-menu{
        height:200px;
        overflow-y:auto;
    }
}

Upvotes: 26

Devesh
Devesh

Reputation: 4560

What I can suggest is in place of hard coding height in pixels you can take the advantage of the view port height like adding this style to your dropdown-menu item or add at the class level

Inline

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

For every dropdown

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

Upvotes: 15

vishal Nagarkar
vishal Nagarkar

Reputation: 241

Use max-height instead of height:

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

Upvotes: 24

Vikas Gupta
Vikas Gupta

Reputation: 1231

You can use a custom class for scroll bar for dropdown list.

<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>

This is the custom css class.

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

check this JSFIDDLE

Upvotes: 1

Related Questions