Topic: Navbar with a search input field of full (remaining) width

Steve06 free asked 7 years ago


Hello, I've studied the documentation on MDB's navbar but couldn't find the following customization I am looking for: From left to right, I'd like my navbar to have, in the same row, branding (left-aligned), search bar of full remaining width (i.e. that uses up all the available horizontal space), and a few buttons that are right-aligned. Any pointers or example code on how to realize this would be much appreciated. Steve

Edyta Dabrowska free answered 7 years ago


Hi, I checked in the console and the problem is here: <ul class="navbar-nav ml-auto" >. 'ml-auto' has set auto margin. Try setting 'ml-auto' according to what you need.

Steve06 free answered 7 years ago


Well what you suggested in the first line of your response is already the case. Re the second line, I haven't tried @media for now but just put style="width:100%" in both the form and input tags. The bar is wider now, but not full width. I am not clear what's limiting it. This is the improved status quo.
<nav class="navbar navbar-toggleable-md navbar-dark bg-primary">
    <div class="container">
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav1" aria-controls="navbarNav1" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <a class="navbar-brand" href="#">
            <img src="logo.png" height="40px"><span style="width:3em;"> </span><strong>Site name</strong>
        </a>
        <form class="form-inline waves-effect waves-light" style="width:100%">
            <input class="form-control" type="text" placeholder="Search" style="width:100%">
        </form>
        <div class="collapse navbar-collapse" id="navbarNav1">
            <ul class="navbar-nav ml-auto" >
                <li class="nav-item">
                    <a class="nav-link">Home</a>
                </li>
                <li class="nav-item active">
                    <a class="nav-link">Take the Tour<span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link">About</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link">Help</a>
                </li>
                <li class="nav-item dropdown btn-group">
                    <a class="nav-link dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Profile</a>
                    <div class="dropdown-menu dropdown" aria-labelledby="dropdownMenu1">
                        <a class="dropdown-item">Action</a>
                        <a class="dropdown-item">Another action</a>
                        <a class="dropdown-item">Something else here</a>
                    </div>
                </li>
            </ul>    
        </div>
    </div>
</nav>

Edyta Dabrowska free answered 7 years ago


Hello, To make buttons to be right-aligned please put form first and then buttons and change mr-auto class to ml-auto. To make search input to have 100% width try changing width for appropriate @media. Regards,

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No