Major Productions
Major Productions

Reputation: 6042

Bootstrap 4 - widening a navbar's inline form input

I have a search input with the following (mostly standard) code:

<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
</button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <!-- links -->
        <form class="form-inline my-2 my-lg-0" action="{{ path('_store_search_results') }}">
            <div class="input-group">
                <input name="search" class="form-control" type="search" placeholder="Search" aria-label="Search">
                <div class="input-group-append">
                    <button class="btn btn-burnt-orange my-2 my-sm-0" type="button"><i class="far fa-search"></i></button>
                </div>
            </div>
        </form>
    </div>

I'd like the input to be wider, but I'm not sure how to do it. I've tried giving my input-group div a row class, with the input itself having a col-3 class, but that actually shrinks the input with rather than widen it. I'm not sure what else to try.

Upvotes: 0

Views: 844

Answers (1)

Carol Skelly
Carol Skelly

Reputation: 362360

Use the utility classes such as d-inline w-100 as needed. If you don't want the input to be full width, use w-50, w-75, etc...

<nav class="navbar navbar-expand-md navbar-light bg-faded">
    <a href="/" class="navbar-brand">Brand</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <!-- links -->
        <form class="mx-2 my-auto d-inline w-100" action="">
            <div class="input-group">
                <input name="search" class="form-control" type="search" placeholder="Search" aria-label="Search">
                <div class="input-group-append">
                    <button class="btn btn-burnt-orange my-2 my-sm-0" type="button"><i class="fas fa-search"></i></button>
                </div>
            </div>
        </form>
    </div>
</nav>

Demo: https://www.codeply.com/go/SW2f1PJUA3


Also see: Bootstrap 4 — how to make 100% width of the search input in navbar?

Upvotes: 2

Related Questions