tags:

views:

111

answers:

3

Hi,

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?

A: 

Try adding the option select { display:block; width:100%;} I'm not sure if it works, but I think it should.

Ben Fransen
A: 

Works for me here: http://jsbin.com/eraru

select {
    width: 100%;
}
nickf
works for me too. Shay, which browsers are you using?
o.k.w
+2  A: 

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.

DKSRathore
That was the problem. The parent element didn't have a width defined. Nice catch!
Shay Friedman