简体   繁体   English

如何使用javascript或CSS更改选择标签中的选项宽度?

[英]how to change option width in select tag with javascript or css?

How may I change the "option" tag width from select tag? 如何更改select标签的“ option”标签宽度?

I need to set the size of the box shown below to be smaller than the width of the "select". 我需要将下面显示的框的大小设置为小于“选择”的宽度。

<select id="Select" style="width: 120px;">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="5">4</option>
</select>

Thanks! 谢谢!

This should help. 这应该有所帮助。

#select option { 
    width:100px
}

Not sure what width are you referencing to, but here is some jQuery since you mentioned it in the tags: 不知道您要指的是什么宽度,但是这里有一些jQuery,因为您在标记中提到了它:

${"#Select option"}.something(); //will select all of the options tags in your <select>
${"#Select option:eq(1)"}.something(); // will select an option tag with specified index
 //(1 in the example, index is zero-based)  

Check the jQuery documentation for the list of available functions. 查看jQuery文档以获取可用功能列表。 For example, width("100px") will set width of selected elements. 例如,width(“ 100px”)将设置所选元素的宽度。 Not sure if that's what you're asking. 不确定这是否是您要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM