Options chosen will vanish in a multi-select drop-down tag with a scroll bar in HTML

I need assistance with my multiple drop-down select tag issue.

.CustomStyle {
  overflow-x: scroll;
  width: 16%;
}
<select multiple size="5" class="CustomStyle">
  <option>Option 1</option>
  <option>Option 2</option>
  <option>Option 3</option>
  <option>Option 4</option>
  <option>Option 5</option>
  <option>Option 6</option>
</select>

When I select an option, the text to the right disappears. I have multiple drop-downs on my website and I do not want this text disappearance to occur. Is there a way to prevent this using HTML or CSS rather than using custom JavaScript code? If so, how can I achieve this?

Answer №1

Encountering an issue in Chrome, unsure of the cause.

A potential solution is to apply float: left; min-width: 100%; to the <option> element style.

Using float: left disrupts the default layout behavior of <option> tags within <select>, while min-width: 100% enhances visual appeal by ensuring complete highlighting of selected <option> even when shorter than the <select> width.

Notably, this approach addresses Chrome and IE11 compatibility, although it may not resolve the issue for IE10-, and Firefox due to lack of support for horizontal scroll in <select>.

.Something {
  overflow-x: scroll;
  width: 16%;
}

option {
  float: left;
  min-width: 100%;
}
<select multiple size="5" class="Something">
  <option>Optionfghfghfgdgdffyuujkyujg 1</option>
  <option>Optionfghfghfgdgdffyuujkyujg 1</option>
  <option>Option n fgnfn ghdnghd ngdh 2</option>
  <option>Optionfghfghfgdgdffyuujkyujg 1</option>
  <option>Option n fgnfn ghdnghd ngdh 2</option>
  <option>Option n fgnfn ghdnghd ngdh 2</option>
</select>

Answer №2

One issue that has been noticed is that horizontal scrolling for <select> elements seems to be buggy in Edge/Chrome, and is not supported at all in Firefox.

An alternative solution that works across all browsers is to wrap the select element in a <div> and apply CSS styles there instead:

.Something {
  overflow-x: auto;
  overflow-y: auto;
  width: 20%;
  height: 100px;
}

.Something > select {
  overflow-y: hidden;
}
<div class="Something">
    <select multiple size="6">
      <option>Option 1</option>
      <option>Option 2</option>
      <option>Option 3</option>
      <option>Option 4</option>
      <option>Option 5</option>
      <option>Option 6</option>
    </select>
</div>

It is important to note that some adjustments need to be made for this to function properly. The size attribute of the <select> should match the number of options, and the <div> should have a specified height.

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

Tips for resolving issues with storing data in a text box that is constantly being added to

Can someone please assist me with this issue I'm facing? I am using isset to check if the index is defined, but it stores 0 instead of saving the value of the textbox. How should I tackle this problem? If I don't check if the index is defined and ...

Is it possible to retrieve the createdAt timestamp without displaying the 'GMT+0000 (Coordinated Universal Time)'?

After conducting an extensive search, I have yet to find a satisfactory answer. My goal is to configure it without including the CUT time. {name: "Registered:", value: `${user.createdAt}`}, {name: "Joined:", value: `${message.guild.joinedAt}`} Presently, ...

Breaking down arrays using the JADE Template Engine

Currently, I am utilizing the JADE template engine in conjunction with ExpressJS. I am attempting to pass an array to my JADE template like so: var data = { "labels" : ["Label 1", "Label 2"] }; res.render('index', {data: data}); The struct ...

When executing `npm run start`, a blank page appears exclusively on the server

I recently set up a Vue landing page on my Mac. In the terminal, I navigated to the folder and executed "npm install" and "npm run dev", which ran without any issues. However, when trying to do the same on a managed server, I encountered challenges with t ...

Tips for inserting a value into a specific location within an array using JavaScript

I am working with an array of objects that looks like this: const array = [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]; My task is to add a new entry to this array, but it needs to be inserted at a specific position. For instance, when adding { ...

How to associate an object with a component in Angular2/TypeScript using HTTP

I am currently working on displaying a list of item names retrieved from a REST API. By utilizing the map function on the response observable and subscribing to it, I was able to obtain the parsed items object. Now, my challenge is how to bind this object ...

Angular animations do not seem to be functioning properly with ng-show when changing the class using ng-class

I need assistance in creating a slider for a list of objects using ng-show and animations. The current setup works smoothly when the objects slide in one direction. However, I am facing issues when trying to implement the functionality for users to slide ...

The Ajax success function is failing to trigger after receiving a 200 network response

I have a basic HTML page that loads jquery 3.3.1 and an external script file called script.js. I am using a simple node http-server to serve the static page. The data.json file is also in the same folder as the HTML file. However, even though the network c ...

Issue with ReactJS on the server side rendering

Could someone please help me understand my current issue? On the server side (using Node.js), I have the following code: var React = require('react'); var ReactDOMServer = require('react-dom/server'); var TestComponent = React.create ...

When I click on the button, the page reloads instead of executing the essential code

On my website, there is a settings page where users can edit their profiles. After editing, they click the update button which triggers the updateProfileData function. This works smoothly in Chrome browser, but in Firefox, the page reloads as soon as the b ...

How can one effectively overcome the constraint in HTML5 canvas that prevents altering the positions of previously sketched elements?

I am currently working on creating a wind map that displays data from seven different weather stations. My goal is to develop a fluid and interactive map similar to the ones found in this animation or this animation. In my research, I came across an artic ...

Cannot populate Kendo Menu with images due to dataSource imageUrl not recognizing the content

I have integrated Kendo controls into my application, specifically a Menu control with a datasource in my controller. Currently, I am passing the relative path of URL for imageUrl. However, as the application has grown, there are multiple calls being made ...

Problem with div selection and dynamic content in Rails 5

Currently, I am working on developing an application using Rails 5 and Ruby 2.4.0 with Bootstrap 4 Alpha 6 integration. The issue I am facing involves a dynamic select box that loads information about the selected item into a div below it. However, each t ...

Vue is actively eliminating a background image through the use of the style attribute

There appears to be an issue where Vue is removing both the style attribute and the background image from this tag. <section style="background: url(images/banners/profiles/profile-banner-1.png);" class="profile-banner flex items-end md:items-end md:j ...

Tips for customizing bootstrap's fixed navbar-default to ensure that the list items align downwards:

Is it possible to customize the bootstrap fixed navbar-default so that the li elements align downward instead of at the top? If you have any corrections or custom solutions, I'd love to see them! Feel free to share your code on platforms like CodePen, ...

Creating an automated sequence of $http requests to sequentially retrieve JSON files with numbered filenames in Angular 1.2

I have a series of JSON files (page1.json, page2.json, etc.) that store the layout details for our website pages. Initially, I would load each page's data as needed and everything was functioning smoothly. However, it is now necessary for all page da ...

When the screen size changes, the centrally aligned position of sticky elements does not stay consistent

It has come to my attention that when centrally aligning an element with position sticky, the alignment can start to malfunction upon reducing the screen width past a certain point, depending on the width of the element. Unlike position: fixed, the sticky ...

Chrome not displaying Bootstrap dropdowns correctly

Lately, I've been exploring Bootstrap and experimenting with its dropdown menus. Typically, I use Chrome for my work but encountered a strange issue with how Chrome is handling my dropdown menus. This forced me to temporarily switch to Edge. Here&apos ...

Issue with Rails manifest assets being undefined or not recognized as an object when making an AJAX request in Internet Explorer 8

I am attempting to retrieve the file names of certain files using ajax from the Manifest.json file. Our file names are digested, which is why I need to access them this way in order to use ajax later on. Here is the code snippet I am currently using: $.aj ...

Overriding the w-4xl with sm:text-2xl in Tailwind CSS

Struggling to achieve responsive design on my Pages, especially with changing text size when the screen is small. I've been following all the correct steps and maintaining the right order. However, whenever I set 'sm', it seems to override a ...