使水平单选按钮小部件具有固定宽度

时间:2014-06-16 18:47:41

标签: html5 jquery-mobile

我的页面中有一个水平单选按钮小部件,如下所示:

<form>
  <fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
    <input name="tool-selector" id="tool-selector-1" value="1" type="radio" checked>
    <label for="tool-selector-1">1</label>
    <input name="tool-selector" id="tool-selector-2" value="2" type="radio">
    <label for="tool-selector-2">2</label>
    <input name="tool-selector" id="tool-selector-3" value="3" type="radio">
    <label for="tool-selector-3">3</label>
    <input name="tool-selector" id="tool-selector-4" value="4" type="radio">
    <label for="tool-selector-4">4</label>
    <input  name="tool-selector" id="tool-selector-5" value="5" type="radio">
    <label for="tool-selector-5">5</label>
    <input name="tool-selector" id="tool-selector-6" value="6" type="radio">
    <label for="tool-selector-6">6</label>
    <input name="tool-selector" id="tool-selector-7" value="7" type="radio">
    <label for="tool-selector-7">7</label>
  </fieldset>
</form>

我希望它始终跨越页面宽度,而不是如果屏幕太宽或者如果它太窄则溢出到下一行,则不会到达行尾。这是可能的,如果是的话,怎么办呢?

感谢。

1 个答案:

答案 0 :(得分:2)

工作示例:http://jsfiddle.net/Gajotres/4KahY/

HTML:

<form>
  <fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
    <input name="tool-selector" id="tool-selector-1" value="1" type="radio" checked>
    <label for="tool-selector-1">1</label>
    <input name="tool-selector" id="tool-selector-2" value="2" type="radio">
    <label for="tool-selector-2">2</label>
    <input name="tool-selector" id="tool-selector-3" value="3" type="radio">
    <label for="tool-selector-3">3</label>
    <input name="tool-selector" id="tool-selector-4" value="4" type="radio">
    <label for="tool-selector-4">4</label>
    <input  name="tool-selector" id="tool-selector-5" value="5" type="radio">
    <label for="tool-selector-5">5</label>
    <input name="tool-selector" id="tool-selector-6" value="6" type="radio">
    <label for="tool-selector-6">6</label>
    <input name="tool-selector" id="tool-selector-7" value="7" type="radio">
    <label for="tool-selector-7">7</label>
  </fieldset>
</form>

的JavaScript:

.ui-controlgroup-controls  {
    width: 100% !important;
}

// This number shoud reflect 100 divided with number of controlgroup radio elements
.ui-controlgroup-controls .ui-radio {
    width: 14.25% !important;    
}

.ui-controlgroup-controls .ui-radio label {
    text-align: center !important;    
}