Expanding the search bar in a navbar with Bootstrap 4

How can I make my search input wider? Here is the code I am using:

<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 have tried adding a row class to the input-group div and giving the input a col-3 class, but this actually makes the input narrower. Any suggestions on how to widen it instead?

Answer №1

Don't forget to utilize utility classes like d-inline w-100 when necessary. If you prefer the input not to be full width, consider using w-50, w-75, and so on...

<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="SupportedContent">
        <!-- 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:


Check out this link too: Bootstrap 4 — how to make 100% width of the search input in navbar?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error occurs in Javascript when attempting to execute javascript code using PHP's echo and an unexpected identifier token is encountered

Currently, I am trying to insert a div into the page when a specific condition is met in PHP: if ($var == 0) { echo '<script>console.log("Test."); var res = document.getElementById("response"); res.innerHTML = "<div class='h ...

Getting elements in order with bootstrap

Can you help me align the "Format Example" string with the textual labels of the input fields without using static width in AngularJS with Bootstrap? The current alignment is right-justified but I would like it to be more dynamic as shown in the screenshot ...

Tips for keeping my wordpress menu at the forefront

This piece of code is responsible for controlling the main menu on my website. Currently, it's set up so that when I scroll down, the menu disappears, and when scrolling up, it reappears. However, I would like the menu to always remain displayed at t ...

When the width of a single table is large, Bootstrap tables can appear misaligned and not properly

I am facing an issue with displaying two tables side by side. Whenever the width of the first table is too large, the second table is pushed below it. https://i.sstatic.net/w8zwp.png https://i.sstatic.net/SZdZU.png Is there a way to make them stay side b ...

Using JavaScript, insert unique texts into div elements with the same id

I am working with 5 divs that have the id of "correctAnswer". In my array, I have 5 elements. How can I insert these 5 elements into the 5 divs? Here is the approach I am taking. var answers =["David Bowie","AM","Australia","Boneface","Sound City"]; for ...

CSS border not displaying correctly on high-resolution screens

When resizing the browser window, I noticed that the border of certain elements, such as this deposit button, gets clipped depending on the width. It seems that when I adjust the width pixel by pixel, the border appears and disappears with each movement. C ...

Is it possible to trigger a JavaScript function by manipulating the URL of an HTML page?

Imagine this scenario: You have an HTML page located at example.com/test.html that contains several pre-defined JavaScript functions, including one named play(). How can I add JavaScript to the URL in order to automatically trigger the play() function wh ...

Eliminate border-radius property from Bootstrap 4 breadcrumb using Sass styling

Within Bootstrap 4, there exists a Sass variable known as $enable-rounded which "Enables predefined border-radius styles on various components." (https://getbootstrap.com/docs/4.1/getting-started/theming/#sass-options) I need to eliminate the rounded ...

Chrome not handling text wrapping within table cells properly

I'm facing an issue with a table I created using the bootstrap stylesheet. For some reason, the cells are not wrapping correctly in Chrome, although they display perfectly fine in IE and Firefox. You can check it out here: <form action="todos" m ...

Utilizing React JS: Displaying or Concealing Specific Components Based on the URL Path

Is there a way to dynamically change the navbar items based on the URL without having separate navbar components for each side? My current navbar design features 3 links on the left side and 3 links on the right, but I want to display only one side at a ti ...

Determine the specific value of an HTML table cell by specifying the column name for a specific row

One challenge I am facing is dynamically creating a table using JSON without knowing in advance the number of columns and/or rows that will be generated. I have successfully added a clicked event for the row that gets selected. In every table, there will ...

The header, main content, and footer sections expand to occupy the entire page

I am in need of HTML structure that looks like the following: <header></header> <div id='main'></div> <footer></footer> I want all elements to be positioned relatively. The header and footer will have fixed h ...

utilizing jquery for dynamic color changes

Check out the code snippet below, which involves the bootstrap accordion and showcases certain elements within the title section. <dt><span><i class="fa fa-tachometer" aria-hidden="true"></i>&nbsp;&nbsp;Manage</span>& ...

Tricky CSS layout challenge: Creating a flexible width single-line design

How can I create a single-line CSS layout that flows to the right endlessly, with each box occupying a set percentage of the viewport width (e.g. 20%)? To better illustrate, refer to the following diagram: +-----------------------------+ |VIEWPORT ...

Why isn't my .gif animation appearing on Google Chrome? Can anyone suggest a reason for this issue?

const urlToLoad = "winners.php"; const ajaxLoader = '<div class="preloaders"><img src="img/preloader.gif" alt="Loading..."></div>'; $(".page").click(function(){ $(".main").html(ajaxLoader).load(urlToLoad); }); I am trying ...

The list is shifting unexpectedly as the font size transitions

Hey guys, I've created a cool interactive design with six boxes that increase in font size when hovered over. However, this causes the boxes to move around, as you can see in my example. Any suggestions on how to fix this issue? Another thing I notic ...

Load a variety of tiles to create a unique style and background for the

Currently, I am using this function to randomly retrieve an image. <script> window.onload = choosePic; var myPix = new Array( "https://ry3yr.github.io/OSTR/Diarykeepers_Homepage/extrafiles/images/bgfiles/cool_stuff_anim.gif", "https:// ...

The div element is experiencing a resizing issue

I am currently working on the following HTML markup: <div class="card" style="height:100%"> <div class="controlPanelContainer"> <div class="card" style="background-color:yellow;height:200px"> </div> <div class= ...

Convert symbols such as ('), to display them as appropriate special HTML characters

When passing campaign data to my templates using render, the code looks like this: return render(request, self.template_name, {'campaigns': campaigns}) While this works fine most of the time, occasional issues arise with strings like {{ campaig ...

Sending simple form information through AJAX to a PHP web service

Attempting to send form data via jQuery and Ajax to a PHP web service (php file) for echoing the results. This is my index.html file <html> <head> <title>PHP web service &amp; AJAX</title> <link rel="stylesheet" type="text/ ...