I\'m trying to achieve the following:
Just a different approach - FIDDLE.
Used code from the jQuery 'selectable' and adapted it.
Used divs to create the columns.
CSS
#holder .ui-selecting {
background: #e0e6fa;
}
#holder .ui-selected {
background: #d1daf4;
color: white;
}
#holder {
list-style-type: none;
margin: 0;
padding: 0;
width: 270px; }
div {
display: inline-block;
}
li div:first-child {
width: 100px;
color: red;
padding: 3px 3px 3px 10px;
}
li div:nth-child(2) {
width: 120px;
color: blue;
padding: 3px 3px 3px 10px;
}
The first snippet works for two-column select list while the second one can handle multiple columns. Semicolon ;
is used as a separator.
// two-column multiple select list
window.onload = function(){
var s = document.getElementsByTagName('SELECT')[0].options,
l = 0,
d = '';
for(i = 0; i < s.length; i++){
if(s[i].text.length > l) l = s[i].text.length;
}
for(i = 0; i < s.length; i++){
d = '';
line = s[i].text.split(';');
l1 = (l - line[0].length);
for(j = 0; j < l1; j++){
d += '\u00a0';
}
s[i].text = line[0] + d + line[1];
}
};
Working jsBin
// multiple-column multiple select list
window.onload = function(){
var s = document.getElementsByTagName('SELECT')[1].options, l = [];
for(i = 0; i < s.length; i++){
column = s[i].text.split(';');
for(j = 0; j < column.length; j++){
if(!l[j]) l[j] = 0;
if(column[j].length > l[j]){
l[j] = column[j].length;
}
}
}
for(i = 0; i < s.length; i++){
column = s[i].text.split(';');
temp_line = '';
for(j = 0; j < column.length; j++){
t = (l[j] - column[j].length);
d = '\u00a0';
for(k = 0; k < t; k++){
d += '\u00a0';
}
temp_line += column[j] + d;
}
s[i].text = temp_line;
}
};
Working jsBin
This is not simply achievable via CSS and would not be cross-browser compatible. The best solution for this would be overriding the select using jQuery and create a drop down on the fly which could be styled appropriately using <span>
tags or similar.