2017-05-30 5 views
-1

私は2列、ラベルカラムと入力カラムを持つ全幅流体レイアウトでフォームを構築しています。ブートストラップ4 - 最大幅のカラムフォームラベル

ワイドスクリーンの流体レイアウトで、col-2ラベルが大きすぎ、col-1が小さすぎるため問題です。

col-form-labelカラムに最大幅を与える方法はありますか、このカラムにsommeカスタム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> 

ブートストラップ4形式のソース:https://v4-alpha.getbootstrap.com/components/forms/#textual-inputs

感謝!

答えて

0

ブートストラップ4のcol-lg-2の最大幅は16.6667%であり、画面サイズの境界はmin-width: 992pxです。

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> 

幅の値とクラス名を好みに合わせて変更します。

+0

こんにちは。ですから、このオプションを使用すると、次の列の最大幅を変更する必要があるため、別の列を作成する必要があります – Seltix

+0

複数のフォームがありますか?独自の幅を定義し、必要に応じてフォームに適用します。私は例を示すために私の答えを更新しました。 –

+0

こんにちは。私は2つ以上のフォームを持っていますが、私は最初のカラム(col-form-label col-lg-2)をカスタマイズするとフォームに2つのカラムがあるので、 2つめの列もカスタマイズする必要があります(col-lg-10)。最後に、この形式で新しいcol-lg-Xクラスを生成する必要があります。 :) – Seltix