Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a horizontal line in a html select control?

Tags:

html

How do I add a horizontal line (<hr> tag) in the dropdown control or in select control in HTML?

like image 287
willam Avatar asked Nov 30 '10 18:11

willam


People also ask

How do I add a horizontal line in HTML?

The <hr> tag defines a thematic break in an HTML page (e.g. a shift of topic). The <hr> element is most often displayed as a horizontal rule that is used to separate content (or define a change) in an HTML page.

How do you make a straight line in HTML?

To make a vertical line, use border-left or border-right property. The height property is used to set the height of border (vertical line) element. Position property is used to set the position of vertical line. Example 1: It creates a vertical line using border-left, height and position property.

How do you use a horizontal line?

A horizontal line is commonly used in technical analysis to mark areas of support or resistance. A horizontal line runs parallel to the x-axis.

How do you select multiple lines in HTML?

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. NOT multi-select, it's multi-line what he is looking for as he stated in his question.


2 Answers

I've run into this issue before and the only cross-browser way to achieve this is to use unicode box drawing horizontal characters. Browsers don't render spaces between these characters. Of course that also means that your page must accept unicode (utf-8) which is almost a given these days.

Here is a demo, this one using a "light horizontal" box mark:

<option value="" disabled="disabled">─────────────────────────</option> 

There are various unicode box character options you can use as separator which should be rendered without spaces between them:

"─", "━", "┄", "┅", "┈", "┉"

More about unicode box drawing characters here: http://www.duxburysystems.com/documentation/dbt11.2/miscellaneous/Special_Characters/Unicode_25xx.htm

You can also include them using HTML escape chars (copy and paste usually works by inserting the box characters' UTF-8 sequence, which browsers seem to respect, but if that's not an option), this for four light horizontal box marks in a row:

&#x2500;&#x2500;&#x2500;&#x2500;

which renders as

────

like image 20
Edem Avatar answered Oct 25 '22 11:10

Edem


Generally speaking this is not a feature of <select>, most browsers have very poor styling control for that control. In Firefox you can do the following (though doesn't work in other browsers):

<select name="test">     <option val="a">A</option>     <option val="b" class="select-hr">B</option>     <option val="c">C</option>     <option val="d">D</option> </select> 

with CSS:

option.select-hr { border-bottom: 1px dotted #000; } 

But generally speaking, the only method is to put an option in with dashes, and try to make it unselectable.

<select name="test">     <option val="a">A</option>     <option val="b">B</option>     <option disabled="disabled">----</option>     <option val="c">C</option>     <option val="d">D</option> </select> 

See: http://jsfiddle.net/qM5BA/283/

like image 150
Orbling Avatar answered Oct 25 '22 12:10

Orbling