html - Bootstrap 4 - 具有最大宽度的列表单标签

标签 html css bootstrap-4 dynamic-columns

我正在构建一个具有 2 列(标签列和输入列)的全 Angular 流体布局表单。

问题是因为它是宽屏幕的流体布局,col-2 标签太大而 col-1 太小。

有没有办法为 col-form-label 列提供最大宽度,或者我是否需要为该列创建一些自定义 CSS?

简单演示:https://codepen.io/seltix/pen/aWgVjR

<div class="formcontainer">
  
  <div class="form-group row">
    <label class="col-12 col-lg-2 col-form-label">Label</label>
    <div class="col-12 col-lg-10">
      <input class="form-control" type="text" value="">
    </div>
  </div>
  
  <div class="form-group row">
    <label class="col-12 col-lg-2 col-form-label">Longer label</label>
    <div class="col-12 col-lg-10">
      <input class="form-control" type="text" value="">
    </div>
  </div>
  
  <div class="form-group row">
    <label class="col-12 col-lg-2 col-form-label">Longer label (extra)</label>
    <div class="col-12 col-lg-10">
      <input class="form-control" type="text" value="">
    </div>
  </div>
  
</div>

bootstrap 4 表单来源:https://v4-alpha.getbootstrap.com/components/forms/#textual-inputs

最佳答案

bootstrap 4 中 col-lg-2 的最大宽度为 16.6667%,屏幕尺寸边界为 min-width: 992px。您想要做的是使用您的自定义类覆盖该 View 中那些列的最大宽度,如下所示:

CSS

/* Not too wide */
    @media(min-width: 992px) {
      .col-percent-13 {
           max-width: 13% !important;
      }
    }

/* A little bit narrower */
    @media(min-width: 992px) {
          .col-percent-11 {
               max-width: 11% !important;
          }
        }

示例 HTML

<!-- I want all the labels in this form to have a width of 13% -->
  <div class="form-group row">
    <label class="col-12 col-lg-2 col-form-label col-percent-13">Label</label>
    <div class="col-12 col-lg-10">
      <input class="form-control" type="text" value="">
    </div>

<!-- In another form, I want all the labels to be 11% wide -->
  <div class="form-group row">
    <label class="col-12 col-lg-2 col-form-label col-percent-11">Label</label>
    <div class="col-12 col-lg-10">
      <input class="form-control" type="text" value="">
    </div>

根据您的喜好修改宽度值和类名称。

关于html - Bootstrap 4 - 具有最大宽度的列表单标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44259843/

相关文章:

html - Google Gauge 设置字体大小和标签

css - 着色下拉菜单

php - 来自带链接的 JSON 的 AutoSuggest

javascript - jQuery Quicksand 网格对齐问题(基于 Bootstrap 的网站)

javascript - "Vertical accordian"使用 HTML5/CSS3 设计?

css - 如何将 div 对齐到顶部

javascript - 内容丰富的按钮折叠成图标并显示导航选项卡内容

html - Bootstrap 4 卡片 - 在底部对齐内容

javascript - html/javascript/css 中的打包图像流

html - 我试图将图标放在页脚的中心