16

Actually I know the select box width is set by the longest option in the list, but I want to increase the length (width) of a select html element.

I also searched and I understand this code style="max-width:70%" may work but it doesn't work for me.

The code below is mine:

<select class="form-control"style="max-width:70%">
    <option value="1">option 1 </option>
    <option value="2">option 2</option>
    <option value="3">option 3</option>
</select>

3 Answers 3

17

you should use width attribute instead of max-width. correct your code to below sample:

<select class="form-control"style="width:150px">
    <option value="1">option 1 </option>
    <option value="2">option 2sdsdsdsd</option>
    <option value="3">option 3</option>
</select>
Sign up to request clarification or add additional context in comments.

Comments

5

You have to use css property min-width for increasing width of dropdown irrespective of the width of options.

html:

<select class="dropdown">
    <option value="1">option 1 </option>
    <option value="2">option 2</option>
    <option value="3">option 3</option>
</select>

css:

.dropdown{
  min-width: 200px;
}

2 Comments

This is, imo, a better solution; the others will trigger overflow-y behaviour.
Separation of concerns—keeping styling information in a stylesheet—is also far better than an inline style attribute.
-3

This will help you.

    <select class="form control"style="width:70%">
    <option value="1">option 1 </option>
    <option value="2">option 2sdsdsdsd</option>
    <option value="3">option 3</option>
    </select>

1 Comment

As a new user thanks for your contribution. Note however that your answer is a duplicate of Sheida's, which I'm sure you did not see when posting your answer. Furthermore you answer lacks in details. Other people have to parse the HTML in your code block and compare it with the one in the question to understand what do you mean. It would be much more helpful to provide a textual description of the solution and not just the code. Even better with a couple links to the relevant documentation. If you keep this in mind you'll provide more valuable answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.