Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent items from being collapsed in bootstrap 4 navbar toggle

I have a bootstrap 4 navigation bar.In this navigation bar i have a font awesome icon-shopping cart that i don't want to toggle(to go in that 3 lines menu) when the page pass a max-width value(the default responsive navbar from bootstrap).I would like to remain near the menu bar.How can i do this? PS:I will put three ! where the font awesome icon is to help you seeing it.

HTML:

<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="index.php">English Park Cuisine</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="navbar-nav mr-auto">
        <li class="nav-item active">
            <a class="nav-link" href="index.php">Acasa<span class="sr-only">(current)</span></a>
        </li>
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Meniu
            </a>
            <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                <a class="dropdown-item" href="meniu.php">Pizza</a>
                <a class="dropdown-item" href="#">Paste</a>
                <a class="dropdown-item" href="#">Supe</a>
                <a class="dropdown-item" href="#">Ciorbe</a>
                <a class="dropdown-item" href="#">Desert</a>
            </div>
        </li>
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Contact</a>
            <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                <p class="dropdown-item">0746117702</p>
                <p class="dropdown-item">0742112452</p>
                <p class="dropdown-item">0735212352</p>
            </div>
        </li>
    </ul>
    !!!<a href="#"><i class="fas fa-shopping-cart fa-lg" style="color: white;"></i></a>
    <ul class="navbar-nav">
        <li class="nav-item">
            <a class="nav-link" href="#">Login</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">Register</a>
        </li>
    </ul>
</div>

like image 212
Mitca Vicentiu Avatar asked Apr 01 '18 17:04

Mitca Vicentiu


People also ask

How do I stop bootstrap navbar from collapsing?

For navbars that never collapse, add the .navbar-expand class on the navbar. For navbars that always collapse, don't add any .navbar-expand class.

How do I keep my bootstrap navbar fixed?

Set the navbar fixed to the top, add class . navbar-fixed-top to the . navbar class.

How can make navbar float right in bootstrap 4?

ml-auto class in Bootstrap can be used to align navbar items to the right. The . ml-auto class automatically aligns elements to the right.


1 Answers

You need to group the non-collapsible items in a single div, and then use the spacing and order utilities to align it as needed.

https://www.codeply.com/go/SJia0JtI1T

<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
    <a class="navbar-brand" href="#">English Park Cuisine</a>
    <div class="d-flex order-lg-1 ml-auto pr-2">
        <a href="#" class="navbar-text"><i class="fa fa-shopping-cart fa-lg" style="color: white;"></i></a>
        <ul class="navbar-nav flex-row">
            <li class="nav-item mx-2 mx-lg-0">
                <a class="nav-link" href="#">Login</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Register</a>
            </li>
        </ul>
    </div>
    <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="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="index.php">Acasa<span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Meniu
            </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                    <a class="dropdown-item" href="meniu.php">Pizza</a>
                    <a class="dropdown-item" href="#">Paste</a>
                    <a class="dropdown-item" href="#">Supe</a>
                    <a class="dropdown-item" href="#">Ciorbe</a>
                    <a class="dropdown-item" href="#">Desert</a>
                </div>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Contact</a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                    <p class="dropdown-item">0746117702</p>
                    <p class="dropdown-item">0742112452</p>
                    <p class="dropdown-item">0735212352</p>
                </div>
            </li>
        </ul>
    </div>
</nav>

Related: Bootstrap 4 - Navbar items outside the collapse

like image 101
Zim Avatar answered Oct 21 '22 15:10

Zim