简体   繁体   English

Jquery Uniform更改选择大小

[英]Jquery Uniform change select size

How can I change the size of an input select using Jquery Uniform? 如何使用Jquery Uniform更改输入选择的大小?

http://uniformjs.com http://uniformjs.com

<script>
 $('div.selector span', $('#parent_span')).css('width', '600px');
 $('div.selector', $('#parent_span')).css('width', '630px');
</script>

<span id="parent_span">
 <select style="width:630px;">
 </select>
</span>

This is what worked for me: 这对我有用:

set selectAutoWidth : true when creating. 在创建时设置selectAutoWidth : true

eg: 例如:

$("select, input, textarea, input:checkbox, input:radio, input:file").uniform({selectAutoWidth : true});

then give a width to the select. 然后给选择一个宽度。 eg: <select id="xx" style="width:70px;"> 例如: <select id="xx" style="width:70px;">

使用CSS更改div.selector span宽度,但您也必须考虑父标记的宽度。

It is bad practice to use inline styling. 使用内联样式是不好的做法。 Here is the proper way to do it according to the Uniform docs: 根据统一文档,这是正确的方法:

If you want to specify a size of a select element and then have Uniform wrap it appropriately, there will be some difficulty. 如果你想指定一个select元素的大小,然后让Uniform适当地包装它,那将会有一些困难。 The size of the element needs to get detected and then will be changed by Uniform. 需要检测元素的大小,然后由Uniform更改。 For this to happen, it is suggested you do one of these solutions when you have issues. 为此,建议您在遇到问题时执行其中一种解决方案。

  • Set a custom inline width for the element () (bad practice) 为元素设置自定义内联宽度()(不良做法)

    OR 要么

  • Use two css rules; 使用两个css规则; select { width: XXpx } and .selector select { width: 100% } 选择{width:XXpx}和.selector select {width:100%}

So using the second option, in your css file do: 所以使用第二个选项,在你的css文件中执行:

#parent_span select {width:630px;)
#parent_span .selector select {width:100%;}

The trick is the 630px is used to build the wrapping Uniform div and then the second css rule kicks in which makes the select tag take 100% inside it. 诀窍是630px用于构建包装Uniform div然后第二个css规则踢,这使得select标签在其中占据100%。

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

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