Adjusting the width of the dropdown search in autocomplete functionality

I'm currently working on creating a search bar with autocomplete functionality similar to Google's. However, I've encountered an issue where the dropdown menu doesn't expand as wide as the search bar.

This works perfectly fine on Microsoft Edge, but for some reason, it's not functioning properly on Google Chrome.

I've attempted to adjust the width settings to 'auto' and 'device-width', but there seems to be no change in the width of the autocomplete dropdown.

.input-group-btn{ width:auto;

}

<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta name = "viewport" content = "width=device-width, inital-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<style>
body{
background:#202a3f;
}
.container{
margin-top:200px;
}
.glyphicon-search{
font-size:20px;
}

.btn-default{
background: orange;
width:100px;
padding:12.5px;
}

.form-control{
padding:25px;
font-size:20px;

}

.input-group-btn{
width:auto;


}

}
.navbar {
  overflow: hidden;
  background-color: #333;
}

.navbar a {
  float: left;
  font-size: 16px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

.dropdown {
  float: left;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 16px;  
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  margin: 0;
}

.navbar a:hover, .dropdown:hover .dropbtn {
  background-color: red;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content a {
  float: none;
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.dropdown-content a:hover {
  background-color: #ddd;
}

.dropdown:hover .dropdown-content {
  display: block;
}
}
</style>
</head>
<body>
<div class="navbar" >
  <a href="#home" >Home</a>
  <a href="#favorites">Favorites</a>
  <div class = "dropdown">
<button class="dropbtn">Genre
<i class = "fa fa-caret-down"></i>
</button>
<div class ="dropdown-content">
<a href="#">Drama</a>

  </div>
  </div>
</div>

  <div class="container">
    <form action="/action_page.php">
<div class = "input-group">
<input type="text" class = "form-control" placeholder="Search" name="search">
<div class ="input-group-btn ">
<button  type="submit" class = "btn btn-default">
<i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
  </div>



</body>


</html>

Whenever I set the width to 'auto' or 'device-width', the dropdown becomes very small. But, if I specify an extremely large number like 1000px or 30000px, the entire search bar shrinks in width and then the dropdown aligns its width with the search bar.

Answer №1

If you're looking to expand the width of the search input box so that the autocomplete feature fits within 100%, there are a few steps you can take to address this issue. Firstly, ensure that you include the jquery.min.js file to eliminate any jQuery errors that may be appearing in your console. Next, make some adjustments to your CSS and HTML code based on the changes I've made below.

body{
  background:#202a3f;
}

.form {
  float: left;
  width: 100%;
}

.custom-layout{
  position: relative;
  float: left;
  width: 100%;
  border-collapse: separate;
}

.custom-layout button{
  position: absolute;
  right: 0;
  float: left;
}

.container{
  margin-top:200px;
}

.glyphicon-search{
  font-size:20px;
}

.btn-default{
  background: orange;
  width:100px;
  padding:12.5px;
}

.form-control {
  padding:25px;
  font-size:20px;
}

.navbar {
overflow: hidden;
background-color: #333;
}

.navbar a {
  float: left;
  font-size: 16px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

.dropdown {
  float: left;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 16px;  
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  margin: 0;
}

.navbar a:hover, .dropdown:hover .dropbtn {
  background-color: red;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content a {
  float: none;
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.dropdown-content a:hover {
  background-color: #ddd;
}

.dropdown:hover .dropdown-content {
  display: block;
}
<div class="navbar" >
   <a href="#home" >Home</a>
   <a href="#favorites">Favorites</a>
   <div class = "dropdown">
      <button class="dropbtn">Genre
      <i class = "fa fa-caret-down"></i>
      </button>
      <div class ="dropdown-content">
         <a href="#">Drama</a>
      </div>
   </div>
</div>

<div class="container">
   <form action="/action_page.php" class="form">
      <div class = "input-group custom-layout">
         <input type="text" class = "form-control" placeholder="Search" name="search">
         <div class ="input-group-btn">
            <button  type="submit" class = "btn btn-default">
            <i class="glyphicon glyphicon-search"></i></button>
         </div>
      </div>
   </form>
</div>

https://i.sstatic.net/NKuGN.jpg

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

Arranging references in a table using {spring boot and Thymeleaf}

I am encountering a display issue in my user interface: UI problem In this scenario, I specifically need to display Categories.Titre from the Categorie table in the database using the Categories.ID selected from the Produit table, not all elements as show ...

Creating a clear division between the jumbotron and column divs using whitespace in Bootstrap design

Having some issues with my Bootstrap layout. I have a jumbotron div at the top, which looks fine, but the columns and rows underneath are not aligning properly and seem to be wider than they should be. I suspect it might have something to do with the grid ...

"Creating a link to a button with the type of 'submit' in HTML - a step-by-step

Found the solution on this interesting page: In a list, there's a button: <form> <ul> <li> <a href="account.html" class="button"> <button type="submit">Submit</button> ...

The floating label appears distorted when used with a datalist input in Bootstrap 5

How can I get the floating label to display correctly for datalists in Bootstrap 5? Currently, it looks like this... It's working fine without the form-floating class, but I want to use the floating form feature. <div class="form-floating" ...

Having trouble implementing Bootstrap even after including it in my project

It feels somewhat embarrassing to ask this question... Currently working in Visual Studio 2019, I utilized the NuGet Package Manager to incorporate Bootstrap 4.5 into my .Net Core 3.1 Web project. Upon adding it, the following files were included: wwwroo ...

Attempting to utilize JavaScript in order to reset a text input field

I'm having trouble clearing a text field using this function. The alert is working but the field remains unchanged. What could be the issue? This function is designed to work on any text field. <!DOCTYPE html> <html> <head> ...

Creating a Contact Form with Email Submission using Html and Php

Establishing Database Connection $server = 'localhost:8080'; $username = 'root'; $password = ''; $database = 'resort'; $connect = mysqli_connect($server, $username, $password ) or die(mysqli_error.&apos ...

Ways to ensure a <div> element adjusts its height based on inner content dimensions

When using buttons in a chatbot that have text which changes based on selected options, I've encountered an issue where the text length sometimes exceeds the button's space. I'm looking for a way to make the containing div automatically adj ...

How to Align Image and Overlay Div in Bootstrap 4

I'm trying to center an image and a div layer within a parent div, but I'm having trouble getting it to shift from the left side of the column. I've experimented with several methods, but nothing seems to work. Even using the margin auto tec ...

HTML when contenteditable attribute is set to "true" doesn't have a fixed width

I was looking to create a textarea with HTML elements inside it and came across this informative article. My approach involved creating a div element with the attribute contenteditable="true". #call-text-form { height: calc(100vh - 350px); width: ...

css - Arranging pictures in a perfect row

On my webpage, I have 5 images and a div. Currently, the images are displaying one under another, but I want them to appear in a straight line while only showing one image at a time within the div. HTML CODE: <html> <head> <title>My Ci ...

Error: The request to /api/auth/login in Postman failed unexpectedly

As I am working on developing an app using node.js and express, I encountered an error while making post requests in Postman. Cannot POST /api/auth/login%0A Below are the details of my app's structure along with the files involved: app.js const ex ...

Guide on clearing the value of the first textarea and transferring it to the second textarea using JavaScript

I have encountered an issue where the first textarea value is being copied into the second textarea because I am using the same id for the 'add more' functionality. Below is the code snippet: <div id="divShortAnswerOption_Templated"> & ...

Using the CSS property hyphens: auto does not function properly for certain words

Could someone shed light on why the word "Sustainability" is not being correctly hyphenated in the following code snippet? I have tested it in multiple browsers like Google Chrome, FireFox, and Safari, and none of them seem to hyphenate the word, ...

"Customizing the color of the arrow in Bootstrap tooltips

Trying to customize tooltips in twitter-bootstrap, I set the template option of the tooltip with inline styles to achieve red tooltips instead of the default black color: $(document).ready(function(){ options = { container: 'body&ap ...

Link the html slider with a php variable

I am currently in the process of updating my website to improve its appearance. My plan is to replace a current textbox input with a combination of slider and textbox, but I am unsure how to implement it within the existing code. The current code snippet ...

Combine several CSS classes into a single class for easier styling

I have implemented specific styling on my webpage based on the city or state of the user. For instance, if someone is from New Jersey, the background color will be red. Currently, I am achieving this using the following method: Using a combination of HTML ...

Updating the CSS style of an inner DIV using JavaScript

Can you provide guidance on how to modify the background color using JavaScript for the different styles listed below? i) Internal Style sheet and/or ii) External Style sheet I am currently working with the card deck slide show available at https://githu ...

Troubleshooting PHP password change functionality issue

I'm having trouble with my code and need some help identifying the issue. The problem I'm facing is that when I try to set a new password, it doesn't seem to save in my database and I can't log in with the new password. Here's the ...

Using jQuery to update the CSS class for all li icons except for the one that is currently selected

Utilizing Font Awesome Icons within the li elements of a ul Challenge When a user clicks on the user icon, the color changes from black to yellow. If the user clicks on another icon, that one also turns yellow. Is there a way to remove the existing yell ...