Marko Nestorovic
Marko Nestorovic

Reputation: 23

Bootstrap full width dropdown menu

I have a problem I can't solve. Found so many topics related to my problem but couldn't figure out how to solve it. I have bootstrap dropdown menu, with 12 items, I am trying to make full width dropdown menu but dropdown content is going out of website width. Is there any way how I can make them go to another line. I tried with flexbox but couldn't work, I tried with display: table, couldn't work.

            .navbar .navbar-nav {
            margin: 0 auto;
        }

        .navbar .nav-item a {
            color: #FFF;
        }


        .navbar .dropdown-menu {
            background-color: rgba(0,0,0,0.8);
            top: 90%;
        }


        .nav > li.dropdown.show {
          position: static;
        }

        .nav > li.dropdown.show .dropdown-menu {
          display: flex;
        /*  flex-wrap: wrap;*/
          border-radius: 0px;
          width: 100vw !important;
          text-align: center;
          left: 0;
          right: 0;
        }

        .dropdown-menu > a {
          height: 50px;
          line-height: 50px;
          vertical-align: middle;
        }


        .navbar-nav .nav-link {
            padding-right: 0;
            padding-left: 1.8rem;
        }

        .dropdown-item {
            padding-left: 1.8rem;
        }

        .dropdown-item:hover {
            background-color: rgba(0,0,0,0.3);   
        }

And HTML:

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
                    <a class="navbar-brand" href="#">
                    <img class="logo" src="images/gwne.png" alt="">
                    </a>
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="collapse navbar-collapse" id="navbarNavDropdown">
                        <ul class="nav navbar-nav ml-auto mr-5">
                            <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            Channel
                            </a>
                            <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                                <a class="dropdown-item" href="#">Esports News</a>
                                <a class="dropdown-item" href="#">Global Gamer News</a>
                                <a class="dropdown-item" href="#">Girls of the Game</a>
                                <a class="dropdown-item" href="#">Mobile News</a>
                                <a class="dropdown-item" href="#">Tech Report</a>
                                <a class="dropdown-item" href="#">VR Report</a>
                                <a class="dropdown-item" href="#">Gossip Rumors & Reviews</a>
                                <a class="dropdown-item" href="#">Health & Psych Report</a>
                                <a class="dropdown-item" href="#">Teams Leagues & Publishers</a>
                                <a class="dropdown-item" href="#">Point - Counterpoint</a>
                                <a class="dropdown-item" href="#">Tips & Tricks</a>
                                <a class="dropdown-item" href="#">Exclusive Interviews</a>
                            </div>
                            </li>
                            <li class="nav-item active">
                            <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
                            </li>
                        </ul>
                    </div>
                </nav>

Thank you in advance.

Screenshot

Upvotes: 0

Views: 3317

Answers (1)

Taki
Taki

Reputation: 17654

remove display:flex from .nav > li.dropdown.show .dropdown-menu { ( and text-align:center too )and add display:inline to your links

.nav > li.dropdown.show .dropdown-menu {
  /* display: flex;*/
  border-radius: 0px;
  width: 100vw !important;
  /*text-align: center;*/
  left: 0;
  right: 0;
}

.dropdown-menu > a {
  height: 50px;
  line-height: 50px;
  vertical-align: middle;
  display: inline;
}

here's a fiddle : https://jsfiddle.net/28g9f3ko/6/

use media-queries to restore the full width on mobile if you want

Upvotes: 1

Related Questions