Personalized bootstrap input form with dropdown recommendations

Having trouble designing a form with a dropdown menu that displays previous user searches when focused. Struggling to style the HTML/CSS so that the suggestions appear directly under the input box without any spacing.

If you want to see the issues I'm facing, check out this JSFiddle attempt where the suggestions wrap after the navbar.

body {
    margin: 10px;
}

.navbar-container {
    display: flex;
    align-items: center;
}

.d-flex {
    display: flex;
    align-items: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse bg-inverse">
  <div class="container navbar-container">
    <a class="navbar-brand" href="#">
      <img src="https://v4-alpha.getbootstrap.com/assets/brand/bootstrap-solid.svg" width="30" height="30" alt="">
    </a>
    <form class="form-inline d-flex">
      <input class="form-control form-control-sm" type="text" placeholder="Search" id="menu1" data-toggle="dropdown">
      <button class="btn btn-outline-success btn-sm" type="submit">Go</button>
      <ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">HTML</a></li>
        <div class="dropdown-divider"></div>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">CSS</a></li>
        <div class="dropdown-divider"></div>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">JavaScript</a></li>
      </ul>
    </form>
  </div>
</nav>

Answer №1

Ensure that the form includes the .dropdown class as it serves as the parent of the .dropdown-menu.

Check out this link for more information

<nav class="navbar navbar-inverse bg-inverse">
    <div class="container navbar-container">
        <a class="navbar-brand" href="#">
            <img src="https://v4-alpha.getbootstrap.com/assets/brand/bootstrap-solid.svg" width="30" height="30" alt="">
        </a>
        <form class="form-inline d-flex dropdown">
            <input class="form-control form-control-sm" type="text" placeholder="Search" id="menu1" data-toggle="dropdown">
            <button class="btn btn-outline-success btn-sm" type="submit">Go</button>
            <ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">HTML</a></li>
                <div class="dropdown-divider"></div>
                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">CSS</a></li>
                <div class="dropdown-divider"></div>
                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">JavaScript</a></li>
            </ul>
        </form>
    </div>
</nav>

Furthermore, upon upgrading to version 4.0.0, you can eliminate the additional flexbox classes.

Answer №2

body
{
    width: 100%;
    height: 100%;
    background-color: #1e1e1e;
    color: white;
    overflow: hidden;
}

.grd-row
{
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
}
...
</div>

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

What is the best way to increase the top padding of an anchor link?

I need to create a padding-top effect for my div when the link to the anchor is clicked: <a href="#myAnchor">Proceed to my anchor</a> ... <div id="myAnchor"> ... </div> The challenge lies in wanting to add the padding only when ...

"Test your Knowledge" - Interactive Quiz with PHP and MySQL

After spending the last two days working on this project, I find myself stuck with some messy and confusing code. Despite searching through countless resources for explanations, I still haven't been able to find a solution. The task at hand is buildi ...

Why does Typeahead display a JSON object in the input field upon clicking?

My suggestion engine is working well, but I am facing an issue where the json object appears in the input element when I click on an item. I want only the OrgName to show up in the input value. <input class="form-control companySearch" type="text" valu ...

Manipulating the location where a dropdown menu intersects with a button

Is there a way to adjust the drop-down menu positioning so that it aligns with the button on the top right side of the menu pop-up, rather than the top left as it currently does? Below is the code I have borrowed from an example on W3Schools. .dropbtn ...

JS-powered menu links losing color after being clicked

I have a JavaScript rollover switch issue - when I click on the link, the color should stay orange (#f7931d), but it reverts back to grey. What am I missing in my code? CSS: #content-slider { padding-top:5px; height: 240px; width: 359px; ...

I'm trying to display hidden forms on a webpage when a button is clicked using the DojoToolkit, but I'm having trouble figuring out what's going wrong with my code

Currently, I am trying to grasp the concepts of Dojotoolkit and my objective is to display a form when a button is clicked. Upon reviewing other examples, my code seems correct to me; however, there appears to be something crucial that I am overlooking but ...

Is separating Jssor Slider CSS effective?

Having a bit of trouble with the Jssor slider here. I'm trying to separate the slider styles into an external CSS document and running into issues. For instance: <div id="slider1_container" style="position: relative; top: 0px; left: 0px; width: 11 ...

The video controls cannot be seen

I'm encountering an issue while trying to incorporate controls into a full-width HTML5 video. Despite following this example: https://jsfiddle.net/nfouvpe5/, the controls remain invisible. Below is the code snippet I am using: <div class="overlay" ...

Adjusting the height of the carousel images to match the height of the window

I am trying to optimize my webpage by adjusting the carousel so that it fits perfectly within the window without generating a vertical scrollbar. Can anyone provide guidance on how to achieve this? Page: <div id="carouselIndicators" class=&qu ...

Changing the color of a specific span using Angular

I am working with a dynamic mat-table where columns are added and populated on the fly. The table headers are styled using divs and spans. My goal is to change the color of a header to black when clicked, but also un-toggle any previously selected header. ...

Using CSS to show only the central portion of an image

How can I display only the center part of an image with dimensions height=300px and width=520px using CSS or jQuery? I tried searching on Google, but didn't find a solution. Is it possible to show only a 200x130 section from the center of an image us ...

Text field auto-saving within an iFrame using localStorage is not functioning as expected

My goal is to create a rich text editor with an autosave feature using an iframe. Although each code part works individually, I am struggling to combine them effectively. View LIVEDEMO This graphic illustrates what I aim to accomplish: The editable iFram ...

What are some ways to increase the scalability of an HTML form?

My login page is easy to read on larger screens like laptops or tablets, but on mobile devices, users have to zoom in to see the text clearly. I want to make it more scalable, but I'm struggling to figure out how. Here's the HTML code: <!DO ...

Tips for displaying a loading icon prior to the page fully loading

Here is my code that is executed when a button is clicked: <?php if(isset($_POST['click'])) { echo "<div class='spinner-grow' role='status'>"; echo "<span class='sr-only'>L ...

Using javascript to navigate back to the previous page without redirecting to the main page

When utilizing an iframe, I've implemented a back button that triggers the following JavaScript code when clicked: document.getElementById("myframe").contentWindow.history.go(-1); // back While this works as intended, if there are no previous pa ...

CSS animation fails to execute

I created a rotating carousel using CSS. The carousel is constructed using the 'ul' tag. To navigate left or right, I dynamically add a 'li' element to the left or right of the list by cloning the necessary value and appending/prependin ...

Verify if the textbox is empty

Is there a way to verify that the input field with type "text" is not empty before moving to the next page? <input TYPE="text" name="textbox2" align="center"> ........ function HomeButton() { <!--if both textbox1 and textbox2 values are not ...

What is the best way to enhance the appearance of the unordered list within the pagination design?

I'm struggling to apply styles to the ul within the Pagination, no matter what I try, it just doesn't seem to work! Here is an image for reference: https://i.sstatic.net/lQvPn.png I am trying to target the MuiPagination-ul class for styling ...

Eliminating shadow effects caused by excessive scrolling on Android browsers and Cordova platforms

Mysterious Scroll Shadow Issue My webpage is displaying a shadow when I scroll too far up or down. I am using Cordova to show my HTML, but I have noticed this problem on other sites in the Chrome browser as well. Could this be a CSS property causing the i ...

Collection of clickable images that lead to creatively designed individual pages

Being relatively new to JavaScript and jQuery, my knowledge is solid when it comes to HTML & CSS. Currently, I have a page with 20 minimized pictures (with plans to increase to 500+ images) that open into a new page when clicked. Although I have no issues ...