html - Bootstrap 4 行中的居中复选框按钮

标签 html css twitter-bootstrap twitter-bootstrap-4

我正在尝试将复选框作为 Bootstrap 中的按钮居中。我尝试在周围的 div 和输入中使用“text-center”和“center-block”,但没有效果。 (您可以在示例中看到“text-center”和“center-block”在许多地方使用。)

HTML:

    <div class="row grade-selection">
      <div class="col-xs-1"></div>
      <div class="col-xs-2 btn-group text-center" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">K</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary text-center">
          <input type="checkbox" autocomplete="off">1</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input class="text-center" type="checkbox" autocomplete="off">2</label>
      </div>
      <div class="col-xs-2 btn-group center-block" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">3</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary center-block">
          <input type="checkbox" autocomplete="off">4</label>
      </div>
      <div class="col-xs-1"></div>
    </div>
    <div class="row grade-selection">
      <div class="col-xs-1"></div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input class="center-block" type="checkbox" autocomplete="off">5</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary active">
          <input type="checkbox" checked autocomplete="off">6</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary active">
          <input type="checkbox" checked autocomplete="off">7</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">8</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">9</label>
      </div>
      <div class="col-xs-1"></div>
    </div>
    <div class="row grade-selection">
      <div class="col-xs-3"></div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">10</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">11</label>
      </div>
      <div class="col-xs-2 btn-group" data-toggle="buttons">
        <label class="btn btn-primary">
          <input type="checkbox" autocomplete="off">12</label>
      </div>
      <div class="col-xs-3"></div>
    </div>

  </div>
</div>

我创建了一个 fiddle ,并为其中一个 div 突出显示了不同颜色的背景,以便您可以看到缺乏居中的情况: https://jsfiddle.net/rovh1fcw/3/

感谢您的帮助!我确信我忽略了一些简单的事情。

最佳答案

Bootstrap 4 alpha 中的 text-center 类现在为 text-xs-center。还要从列中删除 btn-group,因为这会导致按钮显示为内联..

<div class="col-xs-2 text-xs-center" data-toggle="buttons">
  <label class="btn btn-primary text-xs-center">
  <input type="checkbox" autocomplete="off">1</label>
</div>

演示: http://www.codeply.com/go/ZjGIIW1qeQ

More on upgrading to Bootstrap 4

关于html - Bootstrap 4 行中的居中复选框按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37672930/

相关文章:

html - 如何在网络浏览器上播放声音?

html - 在打印时将某个 HTML 内容移动到另一个工作表中

css - 从链接的一部分中删除下划线

html - 不要将 css 样式应用于子元素

html - 如何在 Bootstrap block 之间设置更多空间?

html - 导航页面内容对齐

wordpress - 我怎样才能让 LESSPHP 与 Wordpress 一起工作?

html - 在段落中放置图像以避免更改行间距

javascript - 我怎样才能让 angular-ui-router 具有空白的 ui-sref 属性?

css - Bootstrap 最佳实践?