Selected Options Disappear In A Multiple Drop-down Select Tag With Scroll Bar In Html
Solution 1:
Not sure why it does that, I can reproduce in Chrome.
This seems to fix it. Setting float: left; min-width: 100%; on the <option> element style.
float: left destroys the default block formatting context behaviour of the <option> tags in the <select>. min-width: 100% just makes it a little more aesthetically pleasing, it ensures that even the <option> tags which have content shorter than the width of the <select> are "fully highlighted" when selected.
P.S. This fixes the issue for Chrome and IE11, won't fix it for IE10- and Firefox as they don't support horizontal scrolling on a <select> element at all :)
.Something {
overflow-x: scroll;
width: 16%;
}
option {
float: left;
min-width: 100%;
}<selectmultiplesize="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>Solution 2:
Horizontal scrolling for <select> elements is buggy in Edge/Chrome, and completely unsupported in Firefox.
A work-around supported all browsers would be to simply wrap it in a <div> and apply some of your CSS there instead:
.Something {
overflow-x: auto;
overflow-y: auto;
width: 20%;
height: 100px;
}
.Something > select {
overflow-y: hidden;
}<divclass="Something"><selectmultiplesize="6"><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></div>Some changes had to be made for this to work. The size attribute of your <select> must match the number of options, and your <div> must have a set height.
Post a Comment for "Selected Options Disappear In A Multiple Drop-down Select Tag With Scroll Bar In Html"