Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ellipsis for overflow text in dropdown boxes

Tags:

html

css

I'm fixing the width of one of my dropdown boxes (yes I know there are cross-browser issues with doing this).

Is there a non-js way to cut off overflowing text and append ellipses? text-overflow:ellipsis doesn't work for <select> elements (at least in Chrome).

select, div {      width:100px;       overflow:hidden;       white-space:nowrap;       text-overflow:ellipsis;  }
<!--works for a div-->  <div>      A long option that gets cut off  </div>    <!--but not for a select-->  <select>      <option>One - A long option that gets cut off</option>      <option>Two - A long option that gets cut off</option>  </select>

Example here: http://jsfiddle.net/t5eUe/

like image 319
pepsi Avatar asked Sep 02 '11 22:09

pepsi


People also ask

How do I add an ellipsis to a text-overflow?

To clip at the transition between characters you can specify text-overflow as an empty string, if that is supported in your target browsers: text-overflow: ''; . This keyword value will display an ellipsis ( '…' , U+2026 HORIZONTAL ELLIPSIS ) to represent clipped text.

How do I handle a long text in DropDownList?

//On focus out set the original width of DropDownList. Apply the Css Class adjust-width to all ASP.Net DropDownLists for which you want handle long text as shown below. Apply the Css Class adjust-width to all HTML SELECT DropDownLists for which you want handle long text as shown below.


1 Answers

If you are finding this question because you have a custom arrow on your select box and the text is going over your arrow, I found a solution that works in some browsers. Just add some padding, to the select, on the right side.

Before:

enter image description here

After:

enter image description here

CSS:

select {     padding:0 30px 0 10px !important;     -webkit-padding-end: 30px !important;     -webkit-padding-start: 10px !important; } 

iOS ignores the padding properties but uses the -webkit- properties instead.

http://jsfiddle.net/T7ST2/4/

like image 157
Alex W Avatar answered Oct 14 '22 09:10

Alex W