Are Multi-line Options in Html Select Tags Possibl

2019-01-12 02:12发布

Is it possible (using HTML only) to display select with options that span multiple lines each?

7条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-12 02:53

What about:

<!DOCTYPE html>
<html>
<body>

<select size="13" multiple>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

</body>
</html>

I don't know if this is what you were looking for, but maybe it could help you.

If you want to select multiple options, you must press Ctrl + click to select more options.

If you want to disable multiselect, just erase the "multiple" parameter from the SELECT tag.

查看更多
Evening l夕情丶
3楼-- · 2019-01-12 02:55

It is not possible using html select control.

You can use a div that can act as a dropdown list using JavaScript and css.

查看更多
老娘就宠你
4楼-- · 2019-01-12 02:55

If your case is around iOS truncating long option text, then the solution from How to fix truncated text on <select> element on iOS7 can help.

Add an empty optgroup at the end of the select list:

You can implement like this:

<select>
  <option selected="" disabled="">option first</option>
  <option>another option that is really long and will probably be truncated on a mobile device</option>
  ...
  <optgroup label=""></optgroup>
</select>
查看更多
走好不送
5楼-- · 2019-01-12 02:55

It would be possible by using some JavaScript with CSS styling on HTML elements, easily done with a framework like Dojo Toolkit. Otherwise, use Radio or Checkbox controls.

查看更多
神经病院院长
6楼-- · 2019-01-12 03:03

As the presentation of a select element is up to the user agent, I'm afraid you can't have that, unless some UA actually implements it. But select as either a ListBox or ComboBox never really had much need for items spanning multiple lines. Furthermore it would greatly confuse users as they are used to one line = one item.

查看更多
来,给爷笑一个
7楼-- · 2019-01-12 03:06

No.

You could use radio buttons instead though, their <label>s can word wrap.

查看更多
登录 后发表回答