Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set Select element width in percentage?

Tags:

html

I have a select element in an HTML page, I'd like to set its width to 100% (via CSS) but it doesn't work and the width only changes according to the width of the longest option. Only when I set a width in pixels, it works.

Is it possible to set the width in percentage? or is there a workaround?

like image 344
Shay Friedman Avatar asked Nov 23 '09 13:11

Shay Friedman


People also ask

Can we give width in percentage in CSS?

The <percentage> CSS data type represents a percentage value. It is often used to define a size as relative to an element's parent object. Numerous properties can use percentages, such as width , height , margin , padding , and font-size .

Can width be a percentage in HTML?

For the width attribute, you can also use percentages, where 100% is the total space available. So, if you wanted an image to be one quarter the width of the window, you could set width to 25% (one quarter of 100% is 25%). The height will be in proportion to the width if you do not set it as well.

How would you set the width of an element to be 100 %?

If you want a block-level element to fill any remaining space inside of its parent, then it's simple — just add width: 100% in your CSS declaration for that element, and your problem is solved.


1 Answers

Check the parent element like where your select option is there. The width of the parent element is the constraint for the child. You need to increase the width of the parent first.

like image 136
DKSRathore Avatar answered Nov 10 '22 17:11

DKSRathore