I am trying to achieve two things with DropDown.
- First I want to Wrap the text in the list of options within a dropdown.
- Second, I want to put a border after every option
and I want to support IE (and other browsers too).
This is because I would have long text in the dropdown and I don't wish to cut them. For that reason, I want to do the aforementioned things.
Something like this:-
http://jsfiddle.net/fnagel/GXtpC/embedded/result/
select the one with "Same with option text formatting, Select an Address". Notice how the options are formatted and have a border-bottom with each of them.
Here is what I tried (Text):-
.myselect {
width: 150px;
overflow: hidden;
text-overflow: ellipsis;
}
.myselect option {
white-space: nowrap;
width: 100% border-bottom: 1px #ccc solid;
/* This doesn't work. */
}
<select name="d" class="myselect">
<option value="sdf" class="test1"> line text How to wrap the big line text </option>
<option value="sdf2" class="test1"> line text How to wrap the big line text </option>
<option value="sdf3" class="test1"> line text How to wrap the big line text </option>
<option value="sdf4" class="test1"> line text How to wrap the big line text </option>
</select>
The currently accepted answer only truncates text with ellipsis and adds a border which doesn't completely solve the problem at hand.
I feel like this is a more complete, more cross-browser compatible answer: Make text in select element wrap when too long?
In a nutshell, you can either do it the right way by using javascript, or do it the easy... not so compatible way by using the css property
white-space: pre-wrap
on your option elements.Note: if you go with using
white-space: pre-wrap
, be sure to add-moz-
and-o-
browser prefixes.Here's what I've come up with as a quick, simple CSS solution (though the Jquery one I've mentioned is more robust and better):