Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 Vertical Navbar

I am trying to create a vertical navbar which collapses at some breakpoint. I have it working up to the point where it collapses, but somehow my content from the next column is not getting stacked up properly.

<div class="row">
    <div class="col-xs-3 col-sm-2 col-md-2 col-lg-1 col-xl-1">
        <div class="container">
            <nav class="nav navbar-light navbar-toggleable-sm">
                <button class="navbar-toggler navbar-toggler-left" type="button" data-toggle="collapse" data-target="#navbarW" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse flex-column" id="navbarWEX">
                    <a class="navbar-brand active" href="~/Views/Forms/ControlPanel.cshtml"><span class="fa fa-home"></span></a>
                    @Html.ActionLink("Create User", "Register", "Account", new { @class = "nav-link" })

                </div>
            </nav>
        </div>
    </div>
    <div class="col-xs-9 col-sm-10 col-md-10 col-lg-11 col-xl-11">
        <h2>Hello There</h2>
        <p>Test test test test test test test </p>
    </div>
</div>

Can someone point out what I am doing wrong here?

Update: Thank you @Zimsystem. Below is what i came up with:

<div class="row h-100">
    <div class="col-2 collapse d-md-flex pt-2 h-100" id="sidebar">
        <nav class="nav flex-column">
            <a class="navbar-link active" href="~/Forms/ControlPanel"><span class="fa fa-home fa-3x ml-3"></span></a>
            @Html.ActionLink("Create User", "Register", "Account", new { @class = "nav-link" })
            @Html.ActionLink("Manage Users", "ManageUsers", "Account", new { @class = "nav-link" })     
        </nav>
    </div>
    <div class="col pt-2" id="wLayout">
        <p>Test test test test test test test </p>
    </div>
</div>
like image 446
Ratan Avatar asked Mar 14 '17 14:03

Ratan


People also ask

How do I move navbar to left in Bootstrap 4?

To move the navbar-brand to the left, in the HTML added class mr-auto to navbar-brand . This worked just fine for me.

How do I center navbar in Bootstrap 4?

Using CSS: In this method, we will use a user-defined class to align items to the center. Then, we will use CSS to align items to the center. We have defined the class navbar-centre.

What is navbar toggler?

Navbar Toggle LabelBootstrap Navbar component is designed for mobile first approach. Therefore, the navbar renders as collapsed on mobile devices. It can be toggled by a hamburger button.


1 Answers

There are various issues that were causing a problem. In the latest Bootstrap 4 (alpha 6) the -xs- infix has been removed so it's just col-3 and col-9, and that was causing the overlay problem. Also, container shouldn't be used inside col-.

<div class="container-fluid">
    <div class="row">
        <div class="col-3 col-sm-2 col-md-2 col-lg-1 col-xl-1">
            <nav class="nav navbar-light navbar-toggleable-sm">
                <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarWEX" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse flex-column mt-md-0 mt-4 pt-md-0 pt-4" id="navbarWEX">
                    <a class="nav-link navbar-brand active" href="~/Views/Forms/ControlPanel.cshtml"><span class="fa fa-home"></span></a>
                    <a href="" class="nav-link">Linnk</a>
                    <a href="" class="nav-link">Linnk</a>
                    <a href="" class="nav-link">Linnk</a>
                </div>
            </nav>
        </div>
        <div class="col-9 col-sm-10 col-md-10 col-lg-11 col-xl-11">
            <h2>Hello There</h2>
        </div>
    </div>
</div>

http://www.codeply.com/go/j9esYkO7Dt

Note: navbar-toggleable-* was replaced with navbar-expand-* in Bootstrap 4 Beta 3 (and newer).


Also see:
Bootstrap 4: responsive sidebar menu to top navbar
How to use CSS position sticky to keep a sidebar visible with Bootstrap 4
Create a responsive navbar sidebar "drawer" in Bootstrap 4?

like image 150
Zim Avatar answered Sep 16 '22 15:09

Zim