Html 如何调整 DropDown <select> 框的宽度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1411484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:50:37  来源:igfitidea点击:

How do I adjust the width of a DropDown <select> box?

htmlxhtml

提问by Elitmiar

I need to adjust the width of a select HTML box without using css, is there a way? I tried size but then it's adjusting the height, and width does nothing? Is there another way?

我需要在不使用 css 的情况下调整选择 HTML 框的宽度,有没有办法?我试过大小,但它正在调整高度,而宽度没有任何作用?还有其他方法吗?

回答by stimms

There is no way to do it in pure HTML as per http://www.w3.org/TR/html401/interact/forms.html#h-17.6. You can set it using the style element, though which is kind of without css in that it is inline.

根据http://www.w3.org/TR/html401/interact/forms.html#h-17.6 ,无法在纯 HTML 中执行此操作。您可以使用 style 元素设置它,尽管它是内联的,但它没有 css。

<select style="width: ....

回答by inkedmn

<style type="text/css">     
    select {
        width:200px;
    }
</style>

Does that not work?

那不行吗?

回答by jao

Add an empty option with enough spaces in it ...

添加一个空选项,其中有足够的空格...

回答by Karthik Sivakumar

If u using jquery, Maths Physics Chemistry

如果你使用 jquery,数学物理化学

This is my select html code. So u have to add another div which contains jquery class name including your class name and apply height and width in your class.

这是我选择的 html 代码。所以你必须添加另一个包含 jquery 类名的 div,包括你的类名,并在你的类中应用高度和宽度。

<div class="ui-select selBox"> 
    <select>
    <option>Maths</option>
    <option>Physics</option>
    <option>Chemistry</option>
    </select>
</div>
.selBox{
 width: 470px !important;
 height: 40px !important;
}

here selBox is my class name and ui-select is jquery class name.

这里 selBox 是我的类名, ui-select 是 jquery 类名。