Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css - set max-width for select

Tags:

css

I have a form with a drop down list of venues and a submit button. They are supposed to be on the same line, but since the list of venues is dynamic, it could become too long and push the button down.

I was thinking of setting a max-width property to the select, but I'm not clear whether this will work in all browsers. Do you have any suggestions on a workaround?

<form action="http://localhost/ci-llmg/index.php/welcome/searchVenueForm" method="post"     class="searchform">
    <select name="venue"> 
        <option value="0" selected="selected">Select venue...</option> 
        <option value="1">venue 0</option> 
        <option value="2">club 1</option> 
        <option value="3">disco 2</option> 
        <option value="4">future test venue</option> 
    </select>
    <input type="submit" name="" value="Show venue!" class="submitButton"  />
</form>

css:

.searchform select {
max-width: 320px;
}

.searchform input.submitButton {
float: right;
}
like image 488
Patrick Avatar asked Apr 07 '10 11:04

Patrick


People also ask

How do I set the width of a selection in CSS?

The select tag is in default method and the long text does not appear fully in html. Also, sometimes due to webpage patterns, we want to increase width of tags. So, we give CSS to select and option tags, in this we set the width in pixel in select and minimum width in option.

How do you set a max-width in CSS?

The max-width property in CSS is used to define the maximum width of an element. The value of the width cannot be larger than the value by max-width. If the content is larger than the max-width then it will go to the next line and if the content is smaller than max-width then it has no effect.

How do you increase the width of a selection?

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).

What is Max-Width 100 in CSS?

Defining "width:100%" means that the width is 100%. Defining "max-width:100%" means that the width can be anywhere between 0% and 100% but no more then 100%.


1 Answers

If the venues are generated on the server side, you can use your server-side scripting to cut them down to a specific maximum character count.

When using pure CSS I'd also try setting overflow:hidden, both on the select and the option elements. Also try setting max-width on the option element. When it works in all non-IE, you can use the usual scripts to add max-width support for IE.

like image 141
chiborg Avatar answered Sep 19 '22 13:09

chiborg