wrkbrs

폼 그룹 너비 맞추기 how to format bootstrap input form - all labels with the same width 본문

Bootstrap

폼 그룹 너비 맞추기 how to format bootstrap input form - all labels with the same width

zcarc 2019. 1. 21. 01:00

how to format bootstrap input form - all labels with the same width




I made a form with Bootstrap 3 and I would like to set the same width to all the labels.

From this:form now

To this: it should look like this

I made a fiddle for this: http://jsfiddle.net/52VtD/4262/

<form id="create_new_campaign" name="create_new_campaign" action="kampagnen.php" method="post" enctype="multipart/form-data">
    <div class="input-group">
              <span class="input-group-addon">Kennzeichen</span>
              <input type="text" class="form-control" placeholder="Kennzeichen" name="data[kennzeichen]" id="kennzeichen">
            </div>
            ...
  </form>



3

This should do the trick:

  .input-group{
      width: 100%;
  }
  .input-group-addon{
      width: 45%;
      text-align: left;
  }
  .form-control {
      width: 55%;
  }

Here's the forked fiddle:

http://jsfiddle.net/6K8sF/

2
<form id="create_new_campaign" name="create_new_campaign" action="kampagnen.php" method="post" enctype="multipart/form-data">
    <div class="input-group" style="width: 100%;">
              <span class="input-group-addon"style="width: 35.1%;">Kennzeichen</span>
              <input type="text" class="form-control" placeholder="Kennzeichen" name="data[kennzeichen]" id="kennzeichen">
            </div>
            <div class="input-group"style="width: 100%;">
              <span class="input-group-addon" style="width: 35.1%;">von</span>
              <input type="text" class="form-control span2" id="von">
            </div>
            <div class="input-group" style="width: 100%;">
                <span class="input-group-addon" style="width: 35.1%;">bis</span>
              <input type="text" class="form-control span2" id="bis">
              </div>
            </div>

            <div class="input-group" style="width: 100%;">
              <span class="input-group-addon" style="width: 35.1%;">Verantwortlicher Produktmanager</span>
              <input type="text" class="form-control" placeholder="Produktmanager" name="data[prod_manager]" id="prod_manager">
            </div>

            <div class="input-group"style="width: 100%;">
              <span class="input-group-addon" style="width: 35.1%;">Verantwortlicher Fachbereich</span>
              <input type="text" class="form-control" placeholder="Fachbereich" name="data[fachbereich]" id="fachbereich">
            </div>

            <div class="input-group" style="width: 100%;">
              <span class="input-group-addon" style="width: 35.1%;">Ansprechpartner Fachbereich</span>
              <input type="text" class="form-control" placeholder="AnsprechpartnerFachbereich" name="data[ap_fachbereich]" id="ap_fachbereich">
            </div>

            <div class="input-group" style="width: 100%;">
              <span class="input-group-addon" style="width: 35.1%;">Ansprechpartner Vertrieb</span>
              <input type="text" class="form-control" placeholder="AnsprechpartnerVertrieb" name="data[ap_vertrieb]" id="ap_vertrieb">
            </div>

            <div class="input-group" align="center" style="width: 100%;">
                <br />
                <button type="submit" class="btn btn-primary">Speichern</button>&nbsp;&nbsp;&nbsp;
                <input type="reset" value="Reset" class="btn btn-warning">
            </div>
  </form>

http://jsfiddle.net/52VtD/4264/

1

their are two ways to set all the labels of same size.

DEMO

1) CSS

.input-group-addon {
    width: 253px;
}

But if the label value text is increase or decrease dynamically, you need to fixed this issue using jQuery.

DEMO

2) jQuery

var max = 0;
$(".input-group-addon").each(function(){
    if ($(this).width() > max)
        max = $(this).width();   
});
$(".input-group-addon").width(max);

0

This is the example I did:

<span class="input-group-addon" style="width: 20%;">Last Name</span>
<input id="lname" type="text" class="form-control input-lg" name="lname" placeholder="Last Name">

I did not alter or made customization on the bootstraps' classes because it affects globally. I hate to see my login page with the same width I stated in the emplyee entry module.



https://stackoverflow.com/questions/22955360/how-to-format-bootstrap-input-form-all-labels-with-the-same-width