Insert form onto a new line within the navigation bar

I have implemented this code for the following:

- Add search form to a new line in small or smaller screen sizes.

- Float the toggle button right in small or smaller screen sizes.

The main issue is that the text input does not expand when the screen size changes to small; it remains at a constant max size of 13rem.

Also, wondering how to align the toggle button to the right. Note: float-right is not working.

<nav class="navbar navbar-expand-sm justify-content-between navbar-light bg-light d-flex flex-row">
    <a class="navbar-brand" href="{{route('homepage')}}">ODekh</a>

    <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>

<form method="get" action="{{route('product.search')}}" id="nav-form" class="form-inline">
    <div class="input-group mb-3">
        <input class="form-control" type="search" placeholder="Search" aria-label="Search" id="search" placeholder="Search Books, Authors" name="search" value="">
        <div class="input-group-append border-0 bg-white">
            <button class="btn btn-outline-secondary" type="submit"><span class="fa fa-search"></span></button>
        </div>
    </div>
</form>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
  <ul class="navbar-nav mr-auto">
    <li class="nav-item">
      <a class="nav-link" href="">Books</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="">Cart</a>
    </li>
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Login</a>
      <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item" href="">My Account</a>
        <div class="dropdown-divider"></div>
        <a class="dropdown-item" href="">Logout</a>

     </div>
  </li>
</ul>

Answer №1

If you're having trouble aligning your toggle button, below is a solution that may help. As for the search input, it's unclear what exactly you're looking to achieve with it on smaller screens. Do you want it to expand or shrink? The idea of expanding on smaller screens seems illogical to me.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">


<nav class="navbar navbar-expand-sm justify-content-between navbar-light bg-light">
    <a class="navbar-brand" href="{{route('homepage')}}">ODekh</a>
    
    <form method="get" action="{{route('product.search')}}" id="nav-form" class="form-inline order-sm-12">
        <div class="input-group mb-0">
            <input class="form-control" type="search" placeholder="Search" aria-label="Search" id="search" placeholder="Search Books, Authors" name="search" value="">
            <div class="input-group-append border-0 bg-white">
                <button class="btn btn-outline-secondary" type="submit"><span class="fa fa-search"></span></button>
            </div>
        </div>
    </form>
    
    <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">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item">
                <a class="nav-link" href="">Books</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="">Cart</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Login</a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                    <a class="dropdown-item" href="">My Account</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="">Logout</a>
                </div>
            </li>
        </ul>
    </div>
</nav>



<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>

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

Different ways to style this form using only CSS

Consider the HTML code below: <form> <p> <label for="id_name">Name:</label> <input id="id_name" maxlength="40" name="name" type="text"> </p> <p> <label for="id_format">Fo ...

Empty the password field

<input name="e_password" id="e_password" type="password" autocomplete="off" /> The password field above is causing some trouble as it gets automatically filled in Mozilla, but not in Chrome and IE11. This seems to be retaining values from previous a ...

The cdkDropList in Angular's drag and drop feature does not support the application of element styles

Just wanted to share my experience in case it helps someone else out there! I've been working on an Angular project where I needed to create a Trello-like application. To enable dragging elements from one list to another, I installed the Angular cdk ...

What is the best way to transition an absolute positioned element from right to center?

When hovering over an overlay element, I want the <h3> tag to appear with a transition effect from right to center, similar to the example shown here. Could someone please assist me in achieving this? Thank you in advance. HTML <div class="row m ...

Faulty Container - Excessive spacing issues

https://i.sstatic.net/Sp23W.png Currently enrolled in a Udemy course on Full Stack Development from scratch. The instructor often makes mistakes that require improvisation, like using <span> instead of <p> next to the sign-in. Additionally, ad ...

Jquery Droppable issue arising with dynamically added DIVs

I am facing a similar issue as described in this question and this one I am trying to implement drag-and-drop and resize functionality. It is working fine for static elements, but I encounter issues when adding dynamic divs. The resize property works prop ...

Tips on incorporating a color picker in HTML using jQuery

Looking to implement an HTML color picker with the help of JQuery. Wondering if there is a simpler method to do this without relying on external JQuery libraries? Experimented with <input type="color"> but encountered issues that prevented it from ...

Creating a dynamic interaction between HTML forms and JavaScript using the onsubmit event handler

Having trouble getting my JavaScript file to fire when clicking the submit button on my simple HTML form. Can anyone provide some assistance? **UPDATED CODES Here is a snippet of my condensed HTML file: <html> <form name="form01" id="form01" ac ...

Expanding the Background Color when Hovered Over

Despite my extensive search on SO, none of the answers I found seem to address my specific situation. In a col-md-2 section where I have a navigation bar, I am trying to change the background color to extend up to the border when hovering. While I can cha ...

JQuery causes Bootstrap carousel to malfunction after dynamically adding attribute to img tag

If you're thinking of sending me to this resource: Bootstrap Carousel not working after adding items dynamically with jQuery, know that the situation described there is different from mine. My issue involves fetching paths for 3 images from a JavaScr ...

Bootstrap 4 Nav Table of Contents with Expand and Collapse Feature

Currently, I am encountering an issue with implementing a button to expand and collapse a "table of contents" in Bootstrap 4. The code I have so far can be viewed here: https://codepen.io/nht910/pen/RwwwyKB Code Snippet: <div class="main-wrapper col- ...

What is the significance of using HttpUtility's HtmlDecode function in my code?

One of my ASP.NET MVC controllers returns a view where I generate some HTML code. For example: @Html.ActionLink(HttpUtility.HtmlDecode("&iquest;Olvid&oacute; su contrase&ntilde;a&#63;"), "ForgotYourPassword", "Account", null, new { style = ...

embedding an Image onto a webpage without requiring a source

How can I incorporate an image into my HTML page and then send it via fax without using the "src" attribute? Any suggestions on converting the image to a byte array and embedding it in the html document? ...

Altering various HTML components with every swipe of SwiperJS

I am new to working with JavaScript and I have integrated a Swiper JS element into my HTML page. Here is the current code I am using: <head> <link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css&quo ...

Is there a way for me to determine which .js script is modifying a particular HTML element?

Let's take a look at a specific website as an example: This particular website calculates value using a .js script embedded in the HTML itself. Upon inspecting the source code by pressing F12, we can locate the element containing the calculated valu ...

An illustration using Bootstrap 5: Cover page design featuring a fixed-top navigation bar and smoothly scrolling content

Struggling with customizing the bootstrap 5 cover page example. I really love the design, especially the header and footer (without toggle, brand staying on a single line, etc.). Want a page with more content scrolling in the middle, while keeping the nav ...

Find out the dimension of an object's width

I have a container that I want to slide in and out of view on the screen when a button is clicked. The challenge is that I do not want to set a specific width for the container as it may vary in size. I attempted to achieve this with the following code, ...

Analyzing - Dynamically Tagging Method - Implementing direct call regulations- Erase enduring variables

https://i.sstatic.net/elGJz.jpg Hello there, I am currently utilizing a Direct call rule within DTM. When I click on a href link that opens in a new window, I want to remove or clear the eVars and events associated with the click. I have implemented custo ...

After transitioning to TypeScript, the CRA app is encountering issues loading CSS files compiled by SASS

My React application was originally created using create-react-app and I had been successfully loading scss files with the node-sass package. However, after deciding to switch to TypeScript following the steps outlined in , my css files are no longer being ...

Do you create a dedicated CSS file specifically for Internet Explorer?

I am currently exploring the best solution for my current situation. Previously, I utilized CSS3 to create rounded corners and drop shadows, but encountered compatibility issues with IE8. As a result, I had to implement CSS3pie to support IE8. However, th ...