Having trouble aligning the unordered list with the input

Can anyone help me troubleshoot my CSS so that the list appears below the input field?

Check out this example

The nested menu in this example is positioned too far to the left and slightly too high. It should be aligned with the bottom of the containing menu.

.combobox-wrapper {
  position: relative;
  width: 20em;
  min-height: 1.5em;
  display: flex;
  align-items: center;
  width: 100%;
  display: flex;
  flex-direction: row;
}

.combobox-label {
  width: 50%;
  padding-top: 0.5em;
}

.combobox-input {
  font-size: 16px;
  font-weight: normal;
  height: 30px;
  padding: 4px 10px;
  width: 50%;
}

.combobox-options {
  position: absolute;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 15em;
  overflow-y: auto;
  left: 0;
  top: calc(100% + 0.25em);
  z-index: 100;
  display: block;
}

.combobox-option {
  padding: 0.25em 0.5em;
  cursor: pointer;
  position: relative;
}

<div class="combobox-wrapper">
   <label for="combobox-input" class="combobox-label">
     Countries
   </label>
   <input id="combobox-input" />
   <ul id="combobox-listbox" role="listbox" class="combobox-options">
     <li tabindex="0" id=":rl:-BZ" role="option" value="BZ" class="combobox-option highlighted"><span>Belize</span></li>
     <li tabindex="0" id=":rl:-BJ" role="option" value="BJ" class="combobox-option"><span>Benin</span></li>
   </ul>
 </div>

Answer №1

Perhaps you're interested in trying out the following:

index.html

<div class="combobox-wrapper">
<div>
<label for="combobox-input" class="combobox-label">
Countries
</label>
<input id="combobox-input" />
</div>
<div>
<ul id="combobox-listbox" role="listbox" class="combobox-options">
<li tabindex="0" id=":rl:-BZ" role="option" value="BZ"
class="combobox-option highlighted"><span>Belize</span></li>
<li tabindex="0" id=":rl:-BJ" role="option" value="BJ"
class="combobox-option"><span>Benin</span></li>
<li tabindex="0" id=":rl:-BM" role="option" value="BM"
class="combobox-option"><span>Bermuda</span></li>
<li tabindex="0" id=":rl:-BT" role="option" value="BT"
class="combobox-option"><span>Bhutan</span></li>
<li tabindex="0" id=":rl:-BO" role="option" value="BO"
class="combobox-option"><span>Bolivia</span></li>
<li tabindex="0" id=":rl:-BA" role="option" value="BA"
class="combobox-option"><span>Bosnia and Herzegovina</span></li>
<li tabindex="0" id=":rl:-BW" role="option" value="BW"
class="combobox-option"><span>Botswana</span></li>
<li tabindex="0" id=":rl:-BV" role="option" value="BV"
class="combobox-option"><span>Bouvet Island</span></li>
<li tabindex="0" id=":rl:-BR" role="option" value="BR"
class="combobox-option"><span>Brazil</span></li>
<li tabindex="0" id=":rl:-IO" role="option" value="IO"
class="combobox-option"><span>British Indian Ocean Territory</span></li>
<li tabindex="0" id=":rl:-BN" role="option" value="BN"
class="combobox-option"><span>Brunei Darussalam</span></li>
<li tabindex="0" id=":rl:-BG" role="option" value="BG"
class="combobox-option"><span>Bulgaria</span></li>
</ul>
</div>
</div>

style.css

.combobox-wrapper {
    position: relative;
    width: 20em;
    min-height: 1.5em;
    display: flex;
    align-items: center;
    border-radius: var(--form-field-border-radius);
    outline: none;
    background-color: white;
    width: 100%;
    display: flex;
    flex-direction: column;
  
  }
  
  .combobox-label {

    color: var(--color-text-dark-gray);
    padding-top: 0.5em;
  }
  
  .combobox-input {
    font-size: 16px;
    font-weight: normal;
    color: #4d4d4d;
    background: #ffffff;
    border: 1px solid #828995;
    height: 30px;
    padding: 4px 10px;
    width: 50%;
  }
  
  .combobox-options {

    list-style: none;
    max-height: 15em;
    overflow-y: auto;
    border: 0.05em solid var(--color-bg-gray);
    border-radius: var(--form-field-border-radius);
    left: 0;
    top: calc(100% + 0.25em);
    background-color: var(--color-white);
    z-index: 100;
    display: block;
  }
  
  .combobox-option {
    padding: 0.25em 0.5em;
    cursor: pointer;
  }

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

Experiencing issues with retrieving information from the database

I have a form and query set up to retrieve information from a database. The issue I'm encountering is that it works perfectly when the studentcode is a number, but fails when it's a letter. I'm unsure of what might be causing this problem. A ...

Jquery's remove function fails to function correctly when used on a cloned element

I am facing an issue where I have a list of rows that need to be deleted. However, when I attempted to use jQuery's remove function, it only removed the original row and not its clone. My goal is for the parent element of the parent to be removed when ...

Personalized cursor image using jQuery.css()

I have designed a .png image that I want to use as a custom cursor for a particular element with the class "next". Here is the code I am using, but it doesn't seem to be working. Is there anything important that I may have overlooked? $('.next& ...

Access in-depth data by clicking on a map to get detailed information

Recently, I took on the challenge of managing a golf club website after the original creator had to step away. One urgent issue I need to address is fixing a malfunctioning flash animation that provides information about each hole on the course. My plan is ...

Angular-ui does not support the ng-disable directive

<h3 class="pulse-green-text"><span class="icon ico_pulse_download"></span>VPN Certificate</h3> <div class="vpn-cert" ng-controller="vpnController vpnCert"> <form method="post" name="userform" class="form-horizontal" id="u ...

Is it possible to hide a fixed header on scroll in a mobile device?

I am facing an issue with my Wordpress site where I want the header to hide when the user scrolls. Despite trying various codes, I have been unable to make it work. The reason for wanting to hide the header is that on mobile devices, it causes scroll prob ...

Executing a jQuery script on various elements of identical types containing different content (sizes)

I am currently working on a jQuery script that will center my images based on the text block next to them. Since I am using foundation 5, I have to use a jQuery script to override the CSS instead of using vertical-align: middle. The script looks like thi ...

Retrieve the width of an element once the browser has finalized its dimensions

I am facing an issue with centering a pop-up box perfectly within the window using CSS properties. The code for the pop-up box styling is as follows: #pop_up { position: fixed; display: inline-block; border: 2px solid green; box-shadow: 0p ...

I find myself struggling to manage my javascript dependencies

Currently, I am utilizing NPM along with various angular packages. As per the tutorial on Basic Grid Part 1 at this link, I am encountering challenges. This is my file directory structure: D:/nodeStuff/uiGrid includes: node_modules uigrid.css uigrid.h ...

The toggle checkbox feature in AngularJS seems to be malfunctioning as it is constantly stuck in the "off"

I am trying to display the on and off status based on a scope variable. However, it always shows as off, even when it should be on or checked. In the console window, it shows as checked, but on the toggle button it displays as off Here is the HTML code: ...

Adjust the size of a Highcharts chart before printing

I'm facing an issue with a chart that doesn't have a specified height or width. My goal is to print the graph in a taller and larger size when I click on the print button. I attempted to use setSize() function, but since there are no original di ...

Scrape embedded content within an IFrame on a webpage with Java

Currently, I am interested in crawling the dynamic content within an IFramed webpage; Unfortunately, none of the crawlers I have tested so far (Aperture, Crawl4j) seem to support this feature. The result I typically get is: <iframe id="template_cont ...

Direct your attention towards the bootstrap dropdown feature

I have encountered an issue with using a bootstrap dropdown. I need to focus on the dropdown in order to navigate through its options using the keyboard. However, my current attempt at achieving this using jQuery does not seem to be working when I use $(&a ...

Using JavaScript or JQuery, move an image from one location to another by removing it and adding

Firstly, feel free to check out the JSFiddle example My task involves moving an image with the class "Full" after a div with the class "group-of-buttons" using JavaScript. Here is the snippet of HTML code: <img src="http://i.telegraph.co.uk/multimedia ...

Switch or toggle between colors using CSS and JavaScript

Greetings for taking the time to review this query! I'm currently in the process of designing a login form specifically catered towards students and teachers One key feature I'm incorporating is a switch or toggle button that alternates between ...

Can Vuetify's grid system seamlessly integrate with the Bootstrap grid system?

According to information from the Vuetify documentation: The Vuetify grid draws inspiration from the Bootstrap grid. It involves the use of containers, rows, and columns to organize and align content. If I utilize Bootstrap grid classes in a Vuetify pr ...

Attempting to implement image switching with hover effects and clickable regions

Hey there, I'm currently working on a fun little project and could use some guidance on how to achieve a specific effect. The website in question is [redacted], and you can view the code I've used so far at [redacted]. You'll find a code blo ...

A visually stunning image showcase with dynamic resizing and strategically placed white spaces using the m

I'm attempting to create a responsive image gallery using the Masonry jQuery plugin, but despite reading numerous articles and forum posts on the topic, I can't seem to get it to work properly. The gallery is displaying many blank spaces. My app ...

Creating elegant text in HTML using only CSSLearn how to design stylish text using CSS without any additional code

Can you generate stylish text using just CSS in HTML? Check out this link for a great demonstration of fancy text. ...

CSS Horizontal Menu positioned left losing its background color due to float property

Can you explain why the background color of the ul element disappears when its child elements are floated? I have a vague memory of reading something about floats causing this issue, but I can't recall the details. (JSFiddle) ul { padding-left: ...