jquery - 无论标签长度如何,在 Bootstrap 3 中排列单选按钮

标签 jquery html css forms twitter-bootstrap

我有一个面板元素,其中有 5 行单选按钮,选项 1-5。我希望所有这些行彼此对齐,而不管它们相应标签的宽度如何。我尝试过普通的 Bootstrap 3、jQuery UI 的位置 API 和 jQuery Mobile 的 5 列网格。

供您阅读:http://jsfiddle.net/Muzical/yjyes5rm/2/ 例如:

<label class="control-label">Criteria 1&nbsp;<span class="glyphicon glyphicon-question-sign" title="Tooltip"></span>
    </label>
    <div class="btn-group btn-group-sm ui-grid-d" data-toggle="buttons">
        <div class="btn btn-default ui-block-a label">
            <input class="ui-bar ui-bar-a" type="radio" name="thing1" id="criteria1Rdo1" value="1" />1</div>
        <div class="btn btn-default ui-block-b label">
            <input class="ui-bar ui-bar-a" type="radio" name="thing1" id="criteria1Rdo2" value="2" />2</div>
        <div class="btn btn-default ui-block-c label">
            <input class="ui-bar ui-bar-a" type="radio" name="thing1" id="criteria1Rdo3" value="3" />3</div>
        <div class="btn btn-default ui-block-d label">
            <input class="ui-bar ui-bar-a" type="radio" name="thing1" id="criteria1Rdo4" value="4" />4</div>
        <div class="btn btn-default ui-block-e label">
            <input class="ui-bar ui-bar-a" type="radio" name="thing1" id="criteria1Rdo5" value="5" />5</div>
    </div>

我也拒绝使用布局表,因为那简直就是邪恶,而且这不是 1998 年。我希望发生的是所有按钮都与最宽的标签对齐并且可以在移动设备上使用,可能不会更小比 iPad mini 或类似产品要好。

最佳答案

您需要稍微调整一下您的 html,并在表单上使用类 form-horizo​​ntal。

http://jsfiddle.net/vandigroup/3oepryn4/1/

<form class="form-inline" role="form">
  <div class="radio">
    <label class="btn btn-default">
      <input type="radio" name="thing1"> Option 1
    </label>
    <label class="btn btn-default">
      <input type="radio" name="thing1"> Option 2
    </label>
    <label class="btn btn-default">
      <input type="radio" name="thing1"> Option 3
    </label>
    <label class="btn btn-default">
      <input type="radio" name="thing1"> Option 4
    </label>
    <label class="btn btn-default">
      <input type="radio" name="thing1"> Option 5
    </label>
  </div>
</form>

关于jquery - 无论标签长度如何,在 Bootstrap 3 中排列单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26364048/

相关文章:

javascript - 允许在其标签中使用 HTML 标签的圆环图 JS/Jquery?

javascript - 将每个星号包裹在 span 标签中

jquery - jQuery将网址替换为视频

javascript - 如何重复 `setInterval`?

python - 使用 BeautifulSoup 抓取 IMDb 页面

html - 突出显示整行,不管 rowspan - css

html - 风格 Markdown 的最佳方式

html - 如何创建像这个网站一样的 pin unpin 效果?

php - 从 functions.php 或 style.css 设置 'Update' 或 'Publish' WP 按钮的样式

Javascript 移动设备宽度检查和类删除