Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit Initial width of select list

Tags:

css

select

I have a select list, where some clients have entered insanely long options for them, which breaks the design. I'm wondering if there is a way to set a fixed width on the select widget, but still have the drop down menu it produces still be wide enough to display all of the option.

like image 422
GSto Avatar asked Sep 23 '10 17:09

GSto


People also ask

How do I fix dropdown size?

Widening Drop-down Lists The length of the drop-down box is not big enough to display the entire text. The simple solution is to widen the column that the drop-down box is in. You can adjust the column manually by dragging the border of the column header.

How do you change the width of a selected box?

Answer: Use the CSS :focus pseudo-class By default the size of the <select> element is depend on the size of the largest <option> text. However, sometimes it is useful to set a fixed width to the select box and increase its size back to the original size when the user tries to select some option (i.e. on focus).

How do you set the length of a drop down list in HTML?

The size attribute of the <select> element is used to set the number of visible list items from a drop-down list. A scrollbar would get added if the size is set more than 1. Above, num is the count of the visible list items in the drop-down list.


1 Answers

Since you don't specify what browser support you need, this may or may not be a solution. This works in most browsers IE9+

select {
    width: 100%;
    max-width: 150px;
}

Short and sweet. When expanded, the select will display the whole text (unless it exceeds the viewport!).

like image 73
Jongosi Avatar answered Nov 04 '22 01:11

Jongosi