Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can change width of dropdown list?

I have a listbox and I want to decrease its width.

Here is my code:

<select name="wgtmsr" id="wgtmsr" style="width: 50px;">   <option value="kg">Kg</option>   <option value="gm">Gm</option>   <option value="pound">Pound</option>   <option value="MetricTon">Metric ton</option>   <option value="litre">Litre</option>   <option value="ounce">Ounce</option> </select> 

This code works on IE 6 but not in Mozilla Firefox (latest version). Can anybody please tell me how I can decrease the width of the dropdown list on Firefox?

like image 926
user1844626 Avatar asked Dec 18 '12 11:12

user1844626


People also ask

How do I change the width of a drop-down list in Excel?

Widening Drop-down Lists The simple solution is to widen the column that the drop-down box is in. You can adjust the column manually by dragging the border of the column header.

How do you increase the width of a selection box in HTML?

Answer: Use the CSS :focus pseudo-class By default the size of the <select> element is depend on the size of the largest <option> text. However, sometimes it is useful to set a fixed width to the select box and increase its size back to the original size when the user tries to select some option (i.e. on focus).

How to control the width of the list that drops down?

Create a css and set the value style="width:50px;" in css code. Call the class of CSS in the drop down list. Then it will work. If you want to control the width of the list that drops down, you can do it as follows.

How do I widen the column for a drop-down list?

For example, in the form below, widening the column for the drop-down list changes the size of other form fields. A workaround/alternative for this problem is to use the Merge & Center feature. I can select one or more of the cells adjacent to the drop-down cell and then select Merge & Center on the Home tab.

How do I change the length of a drop-down box?

The length of the drop-down box is not big enough to display the entire text. The simple solution is to widen the column that the drop-down box is in. You can adjust the column manually by dragging the border of the column header.

How do I make a drop down list 270px in HTML?

@Html.DropDownListFor (x => x.Name, new SelectList (new List<string> ()), new {style="width:270px;"} ); Will do the thing. Although better to use css class


2 Answers

The dropdown width itself cannot be set. It's width depend on the option-values. See also here ( jsfiddle.net/LgS3C/ )

How the select box looks like is also depending on your browser.

You can build your own control or use Select2 https://select2.org

like image 30
algorhythm Avatar answered Sep 18 '22 05:09

algorhythm


Try this code:

<select name="wgtmsr" id="wgtmsr"> <option value="kg">Kg</option> <option value="gm">Gm</option> <option value="pound">Pound</option> <option value="MetricTon">Metric ton</option> <option value="litre">Litre</option> <option value="ounce">Ounce</option> </select> 

CSS:

#wgtmsr{  width:150px;    } 

If you want to change the width of the option you can do this in your css:

#wgtmsr option{   width:150px;    } 

Maybe you have a conflict in your css rules that override the width of your select

DEMO

like image 174
Alessandro Minoccheri Avatar answered Sep 20 '22 05:09

Alessandro Minoccheri