Prevent items from being collapsed in bootstrap 4 navbar toggle

前端 未结 2 711
情话喂你
情话喂你 2021-01-13 04:30

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 pa

相关标签:
2条回答
  • 2021-01-13 05:11

    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

    0 讨论(0)
  • 2021-01-13 05:30

    Move your shopping cart outside of the nav collapse div and nest it and the nav collapse in a new div. Then style the shopping cart accordingly, but it won't go away with the nav collapse.

    <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> <!-- New Div !-->
    <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>
        <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>
        <!-- move the anchor outside of the original div but nested inside the new div !-->
        !!!<a href="#"><i class="fas fa-shopping-cart fa-lg" style="color: white;"></i></a>
    </div>
    
    0 讨论(0)
提交回复
热议问题