如何使用SelectBoxIt.js创建100%宽度选择

gro*_*odt 4 html javascript css

使用SelectBoxIt.js创建100%宽度选择框时遇到一些麻烦

即使将CSS宽度设置为100%,选择框也不会填充100%的容器元素.

CSS:

.test1, .test2, .test2 .selectboxit, .test2 .selectboxit-options {
  width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<select name="test2" class="test2">
  <option value="SelectBoxIt is:">SelectBoxIt is:</option>
  <option value="a jQuery Plugin">a jQuery Plugin</option>
  <option value="a Select Box Replacement">a Select Box Replacement</option>
  <option value="a Stateful UI Widget">a Stateful UI Widget</option>
</select>
Run Code Online (Sandbox Code Playgroud)

WIR*_*IRN 10

JS

$(".mySelect").selectBoxIt({ autoWidth: false });
Run Code Online (Sandbox Code Playgroud)

然后css

.selectboxit-container {
    width: 100%;
}

    .selectboxit-container .selectboxit {
    width: 100%;
}
Run Code Online (Sandbox Code Playgroud)


gro*_*odt 5

格雷格·弗兰科(Greg Franko)帮助我解决了这个问题。

您可以在JSBin中看到解决方案。 http://jsbin.com/udapic/1/edit

基本上,您需要像这样禁用autoWidth:

$(".test2").selectBoxIt({ autoWidth: false, copyClasses: "container" });

然后在CSS中将宽度设置为100%:

.test1, .test2, .test2 .selectboxit, .test2 .selectboxit-options { width: 100%; }

  • 我没有拒绝你。但是:这看起来像是您自己的问答文章。请至少在答案中添加相关的代码部分`.selectBoxIt({autoWidth:false});和所使用的CSS`width:100%;`使其独立。 (3认同)