css - Bootstrap 3 btn组宽度

标签 css twitter-bootstrap twitter-bootstrap-3

我有另一个与 Bootstrap 相关的问题。 我想在我的表单中添加单选框和复选框,我希望它们也占表单元素的 100% 宽度。

我添加了这样的按钮组:

<div class="form-group">
    <label class="col-sm-3 control-label">Subscribe</label>
    <div class="col-sm-9">
        <div class="btn-group input-group" data-toggle="buttons">
            <label class="btn btn-success">
                <input type="radio" name="options" id="option1" />Yes</label>
            <label class="btn btn-primary">
                <input type="radio" name="options" id="option2" />Maybe</label>
            <label class="btn btn-danger">
                <input type="radio" name="options" id="option3" />No</label>
        </div>
    </div>
</div>

这给了我很好的类似 radio 的按钮:

但如您所见,它们的宽度是固定的。这可以用 Bootstrap 类修复吗? 同样,这是我的示例代码:http://jsfiddle.net/Misiu/yy5HZ/5/

最佳答案

使用内置的 .btn-group-justified类别:Offical Docs

Make a group of buttons stretch at equal sizes to span the entire width of its parent. Also works with button dropdowns within the button group.

anchor :

<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group"> 
    <a href="#" class="btn btn-default" role="button">Left</a>
    <a href="#" class="btn btn-default" role="button">Middle</a>
    <a href="#" class="btn btn-default" role="button">Right</a> 
</div>

按钮:

To use justified button groups with <button> elements, you must wrap each button in a button group. Most browsers don't properly apply our CSS for justification to <button> elements, but since we support button dropdowns, we can work around that.

<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group">
  <div class="btn-group" role="group">
    <button type="button" class="btn btn-default">Left</button>
  </div>
  <div class="btn-group" role="group">
    <button type="button" class="btn btn-default">Middle</button>
  </div>
  <div class="btn-group" role="group">
    <button type="button" class="btn btn-default">Right</button>
  </div>
</div>

JSFiddle

关于css - Bootstrap 3 btn组宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20804104/

相关文章:

javascript - 如何在后台单击同一页面上的链接时插入新的幻灯片?

html - 在同一行中跨 bootstrap 列对齐多个元素

html - 将元素放在 div 的右侧

javascript - Bootstrap 弹出窗口中关于单引号/双引号的基本 HTML/JavaScript 混淆

css - bootstrap 3 中的输入尺寸较小

html - CSS 下拉过渡不起作用

html - 如何打破div标签内的内容

javascript - Bootstrap 列在 Firefox 中显示不同

html - BS 网格工作不相同

css - Bootstrap 3 和 Less 一起使用