Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep width of SELECT Element small but OPTIONs flexible

Problem:

My dropdown is loaded dynamically has some options that are quite long and this is messing up my page layout. I'd like the size of the select element to be small but when expanded, allow the user to see all the long options. To do this I have set the width of the SELECT to a fixed value e.g width:200px;

Expected/Desired Behavior (Works in Chrome)

enter image description hereActual Behavior in IE8

enter image description here

What I have tried:

select{
    overflow:show;
}
option{
    overflow:show;
    width:1000px;
}

SIMPLIFIED FIDDLE:

http://jsfiddle.net/gCbhq/2/

like image 562
Sajjan Sarkar Avatar asked Dec 14 '12 20:12

Sajjan Sarkar


People also ask

How can I set the width of select box options?

The select tag is in default method and the long text does not appear fully in html. Also, sometimes due to webpage patterns, we want to increase width of tags. So, we give CSS to select and option tags, in this we set the width in pixel in select and minimum width in option.

How do you set the size of a select tag in HTML?

The size attribute specifies the number of visible options in a drop-down list. If the value of the size attribute is greater than 1, but lower than the total number of options in the list, the browser will add a scroll bar to indicate that there are more options to view.


1 Answers

Ok. Not sure if this helps. I'm using Jquery Mobile and my select button is icon-only (= 28px). On IE8 all my options hence where 28px, too.

I fixed it with this:

select { min-width: 150px !important; }

but this only works, because Jquery Mobile hides the select and adds it's own elements "on top".

Alas, here is a fix - http://css-tricks.com/select-cuts-off-options-in-ie-fix/

like image 171
frequent Avatar answered Sep 28 '22 02:09

frequent