CSS droplists are missing their scrollbars

const elements = document.querySelectorAll('.selectBtn');
const options = document.querySelectorAll('.option');
let zIndexValue = 1;

elements.forEach(element => {
  element.addEventListener('click', event => {
    const nextElement = event.target.nextElementSibling;
    nextElement.classList.toggle('toggle');
    nextElement.style.zIndex = zIndexValue++;
  })
})
options.forEach(option => {
  option.addEventListener('click', event => {
    event.target.parentElement.classList.remove('toggle');
    
    const parentElement = event.target.closest('.select').children[0];
    parentElement.setAttribute('data-type', event.target.getAttribute('data-type'));
    parentElement.innerText = event.target.innerText;
  })
})
.select {
  position: relative;
  margin-bottom: 15px;
  width: 250px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.select .selectBtn {
  background: var(--bg1);
  padding: 10px;
  box-sizing: border-box;
  border-radius: 3px;
  width: 100%;
  cursor: pointer;
  position: relative;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  background: #fff;
}
.select .selectBtn:after {
  content: "";
  position: absolute;
  top: 45%;
  right: 15px;
  width: 6px;
  height: 6px;
  -webkit-transform: translateY(-50%) rotate(45deg);
          transform: translateY(-50%) rotate(45deg);
  border-right: 2px solid #666;
  border-bottom: 2px solid #666;
  transition: 0.2s ease;
}
.select .selectBtn.toggle {
  border-radius: 3px 3px 0 0;
}
.select .selectBtn.toggle:after {
  -webkit-transform: translateY(-50%) rotate(-135deg);
          transform: translateY(-50%) rotate(-135deg);
}
.select .selectDropdown {
  position: absolute;
  top: 100%;
  width: 100%;
  border-radius: 0 0 3px 3px;
  overflow-y: scroll;
  overflow-x: hidden;
  background: var(--bg1);
  border-top: 1px solid #eee;
  z-index: 1;
  background: #fff;
  -webkit-transform: scale(1, 0);
          transform: scale(1, 0);
  -webkit-transform-origin: top center;
          transform-origin: top center;
  visibility: visible;
  transition: 0.2s ease;
  box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
}
.select .selectDropdown .option {
  padding: 10px;
  box-sizing: border-box;
  cursor: pointer;
}
.select .selectDropdown .option:hover {
  background: #f8f8f8;
}
.select .selectDropdown.toggle {
  visibility: visible;
  -webkit-transform: scale(1, 1);
          transform: scale(1, 1);
}



body {
  margin: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #eee;
}
 <div class="select">
        <div class="selectBtn" data-type="firstOption">First option</div>
        <div class="selectDropdown">
            <div class="option" data-type="firstOption">1</div>
            <div class="option" data-type="secondOption">2</div>
            <div class="option" data-type="thirdOption">3</div>
            <div class="option" data-type="forthOption">4</div>
            <div class="option" data-type="fifthOption">5</div>
            <div class="option" data-type="sixthOption">6</div>
            <div class="option" data-type="sixthOption">7</div>
            <div class="option" data-type="sixthOption">8</div>
            <div class="option" data-type="sixthOption">9</div>
            <div class="option" data-type="sixthOption">10</div>
        </div>

I'm facing an issue with the scrollbar in ".select .selectDropdown". It doesn't appear and I can't use it. My objective is to display only 5 items by default and have the rest accessible via scrolling. Despite trying multiple approaches, I haven't been able to achieve this. Any assistance on how to accomplish this would be greatly appreciated. Thank you.


The website prompts me to provide more details, but I am unsure of what else to add.

Answer №1

.update .dropdownSelectors {max-height:200px}

For the dropdown to scroll, it is essential to assign a height. Modify the value of 200px according to your requirements.

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

Having trouble getting scrollspy to work properly in Bootstrap 5?

Can anyone help me with this issue? I tried using the code from a Bootstrap example but it's not working properly. I added data-target in JavaScript, and also included data-target on the body element. The code is a direct copy from the Bootstrap 5 sc ...

Creating a plotly.js integration for nuxt SSR: A step-by-step guide

Currently facing issues with setting up plotly.js in my nuxt project. Despite trying various approaches, I keep encountering the error message self is not defined. Installing both plotly.js and plotly.js-dist did not resolve the issue. My attempt to creat ...

Is the webdriver.io waituntil method designed to return a boolean value of true or false

I am working on an automation framework using webdriver.io v5. I need to receive a boolean response from the code snippet below: waitAndCheckForContactToBePresent(contactName) { return browser.waitUntil((value) => { return this.chec ...

There seems to be an issue with the CSS header alignment as the logo is not properly positioned using a top margin of -20px

My goal is to create a header bar that includes an image, a title, and a menu car. I want the bar to be displayed after scrolling 50px down, and I also want the image to be positioned slightly above the wrapping div, showing a bit of it in the top 50px. Ri ...

Show me a way to use jQuery to show the number of images of a particular type that are on a

My webpage features 6 different images, including 4 of various balls such as basketball and baseball. One image is of a truck, while the last one is random. On the page, there is a form with two radio buttons allowing users to select which type of image c ...

Is it possible to extract information from a string with regular expressions?

As I sift through a myriad of arbitrary "Header" data in node. Here's an example of what it looks like: _Aa:GA1.1.78037747.867108, 44907=5xyz; Webstorm-a36041d5=9fbb-48e9-b19e-e3f0a3282151; srce=coolernode; nsid=1234; cookie_data=T%3D1; _gat_PP= ...

Error message: React Native encountered a prop type failure when an invalid prop of type array was passed to the Overlay component

I am brand new to React Native and encountering an error message when opening a specific component. Although it doesn't hinder navigation, I would like to resolve this issue. I suspect it could be related to a syntax or typo error, but pinpointing the ...

Cannot render <Image> inside <Section> component

As a beginner in React, I am attempting to create an app following a tutorial. In my component, I utilized the figure tag but it's not showing up when inspecting element in Chrome. Here are the code snippets: The tutorial includes a div tag as a chil ...

Navigate to designated part of a website using HTML and CSS styling

Consider the following JavaScript code: //Scroll Down button $(window).scroll(function () { if ($(this).scrollDown() > 100) { $('.containerScroll').fadeIn('slow'); } else { $('.containerScroll').fadeOut('slow'); } ...

Node.js is able to read an HTML file, but it seems to have trouble locating and loading

Struggling to load a jQuery file or any file in a node.js read HTML document. After spending considerable time on this issue, I realized that the Google-hosted library file works fine but my local file does not. The problem seems to be related to directing ...

Utilize a custom JQuery script on designated grid displays

I am facing a challenge in implementing a JQuery script on specific Gridviews within my page. The issue lies in the fact that the script is currently being applied to all Gridviews on the page, and I need a way to specify which grids it should apply to. T ...

Designating a certain function to a designated button

On my page, I have three different forms with submit buttons in each. There is a code that is supposed to change the value of a button in a specific form when clicked. However, whenever I click on any submit button, all the values in the buttons of the v ...

Is the line-height percentage relative to the viewport or the font size?

Can anyone help me understand the line-height property better? How does it work when set in %? When using: line-height: normal; line-height: 1.6; line-height: 80%; What is the percentage relative to? ...

Can you provide instructions on how to utilize JavaScript in order to write to a separate webpage?

I need help with a JavaScript function that is supposed to take user input from one web page and write it to another existing web page within the same domain. The function iterates through a for loop correctly and builds the necessary information, but it ...

Utilizing a large logo alongside the NavBar in Bootstrap

Trying to design a sleek navbar that is proportional to the logo size, while also allowing for additional content below it. The jsFiddle link below showcases the current setup. The black line signifies the bottom of the nav bar, which has expanded to matc ...

How can I utilize React to pull information from the Google Taxonomy API?

Seeking assistance with React development, as I am a beginner and looking to retrieve data from this URL and organize it into a tree structure. I not only want to fetch the data but also display it in a tree format. My current code successfully retrieves t ...

What could be causing the HTML <DATALIST> dropdown to display next to its input rather than below it?

I have an input linked to a datalist, and it's functioning correctly. However, when I initially open the dropdown, the option list appears next to (right of) the input. After entering a few characters to narrow down the list, it then shifts below the ...

Get the XML element containing the desired value in the downloadURL

Seeking assistance from experienced individuals regarding XML usage. Admitting to my lack of knowledge in this area, I am a beginner and seeking patience. I have successfully implemented code that loads marker data from a MySQL database and displays it on ...

Utilizing the .fadeOut('slow') method for CSS visibility manipulation

Here is a little JavaScript code snippet that I have: function toggle_visibility(id) { var e = document.getElementById(id); if(e.style.display == 'block') e.style.display = 'none'; else e.style. ...

Should classes/interfaces/functions be consistently prefixed with the App acronym as a best practice?

As I delve into my Angular project, I find myself contemplating the idea of using the App acronym as a prefix for all Classes, Interfaces, and Functions. This practice is commonly seen in tag components, where adding the App acronym helps avoid conflicts i ...