html - 带有文本下方复选框的自定义复选框

标签 html css twitter-bootstrap checkbox bootstrap-4

我正在尝试自定义内联复选框,文本在复选框上方对齐。与文本相比,复选框必须水平居中。它应该看起来像这样:

enter image description here

我尝试添加 <br/>标记并将文本移动到控件上,如下所示:

  <label class="custom-control custom-checkbox">
    <span class="custom-control-indicator"></span>
    <span class="custom-control-description">Check this custom checkbox</span>
    <br />
    <input type="checkbox" class="custom-control-input">
  </label>

没有成功......你可以看到failed plunker here .

This plunker是 bootstrap v4 的普通内联复选框

最佳答案

.custom-checkbox {
  display: inline-flex;
  flex-direction: column-reverse;
  align-items: center;
}
.custom-control-indicator {
  position: static; /* override _custom-forms.scss */
}

... 如果我正确理解您的请求,就可以解决问题。但是,文本和复选框是“垂直”对齐的,而不是“水平”

.custom-checkbox {
  display: inline-flex;
  flex-direction: column-reverse;
  align-items: center;
}
.custom-control-indicator {
  position: static; /* needed to override position:absolute; from 
                     * _custom-forms.scss - bootstrap 
                     */
}
<div>
  <label class="custom-control custom-checkbox">
    <input type="checkbox" class="custom-control-input">
    <span class="custom-control-indicator"></span>
    <span class="custom-control-description">Check 1</span>
  </label>
  <label class="custom-control custom-checkbox">
    <input type="checkbox" class="custom-control-input">
    <span class="custom-control-indicator"></span>
    <span class="custom-control-description">Check 2</span>
  </label>
  <label class="custom-control custom-checkbox">
    <input type="checkbox" class="custom-control-input">
    <span class="custom-control-indicator"></span>
    <span class="custom-control-description">Check 3</span>
  </label>
</div>

关于html - 带有文本下方复选框的自定义复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44801472/

相关文章:

javascript - 控制 bootstrap 确认模式中的确认按钮

java - 创建将在 Web 浏览器中显示的 Java 小程序

javascript - html 和 css slider 未在页面刷新时加载,但在单击 nxt 或 pre 按钮时运行良好?

javascript - 向动态表添加固定表头

javascript - 在 HTML 中放置条件

html - CSS 菜单问题我只是想不通

html - Javascript : a elements inside div: highlight height when hover

css - bootstrap4 Flex 的列高不等

javascript - 工具提示不在底部

html - 将 Bootstrap 类与我自己的分开?