Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing bootstrap's control label width?

Bootstrap has the following CSS:

.form-horizontal .control-label {
  float: left;
  width: 160px;
  padding-top: 5px;
  text-align: right;
}

.form-horizontal .controls {
  *display: inline-block;
  *padding-left: 20px;
  margin-left: 180px;
  *margin-left: 0;
}

It makes my form look like this:

enter image description here

The labels are way off to the right.

Here is how I build the form:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="kez_header">


        <table class="style1">
           <tr>
               <td>
                   <h4> Add Group
                   </h4>
              </td>
               <td align="right" valign="middle">

               </td>
           </tr>
           </table>

             <div id="new_group_view" class="form-horizontal">
             <form class="form-horizontal" method="POST" action="/yourownpoet/web/app_dev.php/register/">
    <div class="control-group">
        <label class="control-label control-label-me required" for="fos_user_registration_form_email" placeholder="Email">Email:</label>
        <div class="controls">
            <input id="fos_user_registration_form_email" class="text-style" type="email" placeholder="Email" required="required" name="fos_user_registration_form[email]">
            <div placeholder="Password" id="fos_user_registration_form_plainPassword"></div>
        </div>
    </div>

    <div class="control-group">
        <label class="control-label required" for="fos_user_registration_form_plainPassword_Enter Password: ">Enter password: </label>
        <div class="controls">
            <input type="password" required="required" name="fos_user_registration_form[plainPassword][Enter Password: ]" id="fos_user_registration_form_plainPassword_Enter Password: " class="text-style">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label required" for="fos_user_registration_form_plainPassword_Verify Password: ">Verify password: </label>
        <div class="controls">
            <input type="password" required="required" name="fos_user_registration_form[plainPassword][Verify Password: ]" id="fos_user_registration_form_plainPassword_Verify Password: " class="text-style">
        </div>
    </div>
</form>
             </div>
    </div>
</asp:Content>

How can I get this normal so that the labels start more like here: http://bootstrap.stage42.net/doc/forms

Thanks

like image 608
user2043533 Avatar asked Feb 05 '13 17:02

user2043533


People also ask

How do I change the width of a form-control in Bootstrap?

For default size . form-control is used, for smaller size we can use . form-control class along with . form-control-sm and for larger size we can use .

How to make input field smaller in Bootstrap?

Use the . input-sm class to set small input field in Bootstrap.

How to reduce the length of input box in Bootstrap?

We can also adjust the size of input elements in bootstrap by the use of classes like . input-lg and . input-sm for adjusting heights and . col-lg* and .


1 Answers

.form-horizontal .control-label width specifies the "how far would be last character of the label text from the left side of the parent container".

.form-horizontal .controls margin-left specifies the "how far would be left border of the field from the left side of the parent container".

This is simplified explanation but should give you enough understanding to take control over your styles.

So you should adjust .form-horizontal .control-label width and .form-horizontal .controls margin-left values proportionally, to move fields and labels inside the container. Proportionally because "space" between label and field should be preserved. Here is example:

.form-horizontal .control-label {
  float: left;
  width: 120px; /* changed from 160px to 120px */
  padding-top: 5px;
  text-align: right;
}

.form-horizontal .controls {
  *display: inline-block;
  *padding-left: 20px;
  margin-left: 140px;  /* changed from 180px to 140px */
  *margin-left: 0;
}
like image 57
Alexander Manekovskiy Avatar answered Sep 17 '22 23:09

Alexander Manekovskiy