views:

656

answers:

3

This is probably a basic CSS question, but I am not fluent in CSS and just seem to be going in circles.

Here's what I have in English: I have a fixed width select element of 400px. The text for each of the options does not fit in that 400px width. I don't get a horizontal scroll bar, it just cuts off the text. How do I get the scroll bar?

Here's what I have in HTML/CSS:

<div>
  <select style="width=400px">
    <option>this text is too wide to fit and gets cut off.....</option>
    ...
  </select>
</div>

I've tried the overflow property, but I'm either using it incorrectly or it doesn't work on the select element.

How do I get the horizontal scroll bar?

+2  A: 
  1. it should be <select style="width: 400px;"> (not "width=")
  2. a regular HTML-select doesn't have a scrollbar, no matter what you do :)
Select0r
`2.a select doesn't have a scrollbar, no matter what you do :)` - So how do you handle multiple selections? `<select multiple><option>Hello1</option><option>Hello2</option><option>Hello3</option></select>`
Andy E
@Andy no fair, `select multiple` is a different beast :)
Pekka
+2  A: 

Form elements are notoriously difficult to style.

For your width setting, you have a small typo. You need

<select style="width: 400px">

Otherwise, I think horizontal scrollbars can't be achieved using a normal select element. You would have to resort to a JavaScript based alternative like SexyCombo, which may be customizable to have a scroll bar. More options here: 11 jQuery Plugins to Enhance HTML Dropdowns

Pekka
sorry, the "width=" is a typo and is not in my actual code. Is it possible to make the select really big to fit all of the text, and make the surrounding div a fixed width/height that has scrollbars?
schmimd04
@schmimd04 That should be possible by giving the surrounding DIV a fixed size and `overflow: auto;` However, it will bring additional issues, such as the arrow button being hidden as well. But try it out.
Pekka
Just don't give the select a "width" and it will be as big as the longest option. Then surround the select with a DIV that e.g. has '"width: 400px; overflow: auto;"'
Select0r
A: 

Untill MS get the select element right in their crap browser: Don´t set an explicit width on the select element.

http://stackoverflow.com/search?q=html+select+element+width

anddoutoi