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>
Set the width of the element in HTML. Use the width attribute in HTML to set the width of an element. You can use the attribute with the following elements: <canvas>, <embed>, <img>, <input>, <video>, etc. You can try to run the following code to implement width attribute in HTML:
How do we set the type of element in HTML? Use the width attribute in HTML to set the width of an element. You can use the attribute with the following elements − <canvas>, <embed>, <img>, <input>, <video>, etc. You can try to run the following code to implement width attribute in HTML −
CSS width property lets you specify the width of input elements in various CSS units such as px, em, rem, etc. Also, it is not dependent on the size of the fonts. If you want to apply the same width to multiple inputs, you can use CSS attribute selectors to select the desired ones.
Note: For input elements, the width attribute is used only with <input type="image">. The width attribute can be used on the following elements: Your browser does not support the video tag.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With