Html 如何设置多选的宽度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11503972/
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 01:41:07  来源:igfitidea点击:

How to set width of a multiple select?

html

提问by pheromix

I want to set default width of multiple select elements :

我想设置多个选择元素的默认宽度:

enter image description here

在此处输入图片说明

How to do that ?

怎么做 ?

回答by Matt

Try this,

尝试这个,

<select multiple="multiple" style="width: 200px;">

or

或者

<select multiple="multiple" style="width: 10em;">

回答by Quentin

The same way as any other element. You write a selector that matches the element (e.g. a select element with a multiple attribute) and then use the width property.

与任何其他元素相同的方式。您编写一个与元素匹配的选择器(例如,具有 multiple 属性的 select 元素),然后使用 width 属性。

Width applies by default to replaced inline elements (such as selects).

宽度默认应用于替换的内联元素(例如选择)。

select[multiple] {
    width: 7em;
}

回答by Yograj Gupta

Try This in css

在 css 中试试这个

select[multiple=multiple] {width: <default width you want>px ;}

回答by Ricardo Fran?a

Take a look at the max-widthproperty on style.

看看上的max-width属性style

Ex:

前任:

<select name=countries  style="max-width:90%;">
 <option value=af>Afghanistan</option>
 <option value=ax>?land Islands</option>
 ...
 <option value=gs>South Georgia and the South Sandwich Islands</option>
 ...
</select>  

More information: How to control the width of select tag?

更多信息:如何控制选择标签的宽度?

回答by Mehmet Burak Ibis

You can use "size" attribute like below:

您可以使用“size”属性,如下所示:

<!DOCTYPE html>
<html>
<body>

<select size="3">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

</body>
</html>