Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML select box is displaying below windows task bar in chrome

I am trying to add an html dropdown using the select tag and unfortunately in chrome I am unable to select option 5 and 6 as they are being displayed below the task bar in chrome on windows. If I add an option 7 then suddenly the list displays above instead of below. enter image description here

This list will always be changing sizes so unfortunately positioning the list higher will not be an option as there is always the possibility of 2 options being hidden. Furthermore, the number of items displayed in the list is before a scroll bar is added is browser specific. See Height of an HTML select box (dropdown)

What I've tried so far:

  • Tried converting the dropdown list to a static list when there are more than 4 options using jquery and setting list size. This however was very ugly.
  • Tried using bootstraps .dropup class but this unfortunately only works with list items not select options
  • Different css hacks but as mentioned earlier the list size is browser specific.

I would rather not add in any external libraries and find some kind of simple Jquery hack to fix this. You can also see what I mean by visiting this jsfiddle link and dragging the display window to the bottom of the screen:

  <div class="form-group">
  <label for="sel1">Select list:</label>
  <select class="form-control" id="sel1">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
     <option>6</option>
  </select>
</div>

https://jsfiddle.net/v9t4rm16/

like image 773
Josh L Avatar asked Oct 25 '16 17:10

Josh L


People also ask

How do I set the default option in select?

The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute. The option that is having the 'selected' attribute will be displayed by default on the dropdown list.

How do you style the option of an HTML select element?

You can style the option elements to some extent. Using the * CSS selector you can style the options inside the box that is drawn by the system. That is true only because the all selector targets the shadow DOM innards, you can target those manually per browser.

How to select element in HTML?

Definition and Usage. The <select> element is used to create a drop-down list. The <select> element is most often used in a form, to collect user input. The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the drop-down list will be submitted) ...

How do I style a selection dropdown in CSS?

There are many ways to design a <select> dropdown menu using CSS. The Dropdown Menu is mainly used to select an element from the list of elements. Each menu option can be defined by an <option> element that can nested inside the <select> element.


1 Answers

Looks like this is an official chrome bug It affects Chrome Version 30-61

I do not think there is an official work around.

If you do not want to wait for the chrome fix, then you could try:

  • Adding white to the bottom of your page so the select has space to expand
  • Adding extra options in the select itself to force chrome to render upwards
like image 195
Jarred Stelfox Avatar answered Oct 20 '22 00:10

Jarred Stelfox