Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap label align left

I have the following markup:

<form accept-charset="UTF-8" action="/task_categories/1" class="form-horizontal" id="edit_task_category_1" method="post"> 
  <div class="row">
    <div class="col-md-4">
      <div class="well">        
        <div class="form-group"><label class="control-label col-sm-6" for="task_category_task_category_users_attributes_0_Enable">Enable?</label><div class="col-sm-6"><input name="task_category[task_category_users_attributes][0][enable]" type="hidden" value="0"><input class="form-control" id="task_category_task_category_users_attributes_0_enable" name="task_category[task_category_users_attributes][0][enable]" type="checkbox" value="true"></div></div>
        <div class="form-group"><label class="control-label col-sm-6" for="task_category_task_category_users_attributes_0_Enable Comment">Enable comment?</label><div class="col-sm-6"><input name="task_category[task_category_users_attributes][0][comments_enabled]" type="hidden" value="0"><input class="form-control" id="task_category_task_category_users_attributes_0_comments_enabled" name="task_category[task_category_users_attributes][0][comments_enabled]" type="checkbox" value="true"></div></div>
        <input id="task_category_task_category_users_attributes_0_user_id" name="task_category[task_category_users_attributes][0][user_id]" type="hidden" value="1">
      </div>
    </div>

    <div class="col-md-4">
      <div class="well">
        <div class="form-group"><label class="control-label col-sm-6" for="task_category_task_category_users_attributes_1_Enable">Enable?</label><div class="col-sm-6"><input name="task_category[task_category_users_attributes][1][enable]" type="hidden" value="0"><input class="form-control" id="task_category_task_category_users_attributes_1_enable" name="task_category[task_category_users_attributes][1][enable]" type="checkbox" value="true"></div></div>
        <div class="form-group"><label class="control-label col-sm-6" for="task_category_task_category_users_attributes_1_Enable Comment">Enable comment?</label><div class="col-sm-6"><input name="task_category[task_category_users_attributes][1][comments_enabled]" type="hidden" value="0"><input class="form-control" id="task_category_task_category_users_attributes_1_comments_enabled" name="task_category[task_category_users_attributes][1][comments_enabled]" type="checkbox" value="true"></div></div>
        <input id="task_category_task_category_users_attributes_1_user_id" name="task_category[task_category_users_attributes][1][user_id]" type="hidden" value="2">
      </div>
    </div>
  </div>
</form>

The problem is the label text does not float left. Even when I add a text-align: left to the containing div, it still does not align left. What may I be doing wrong?

enter image description here

like image 749
Donato Avatar asked Dec 20 '22 02:12

Donato


2 Answers

You need to add a text-align: left style to .control-label.

Because bootstrap gives labels within horizontal forms the text align style using the selector .form-horizontal .control-label, you need to use the same or a more specific selector:

.form-horizontal .control-label{
    text-align: left;
}

JSFiddle

like image 157
George Avatar answered Jan 03 '23 21:01

George


Set the text-align property to the .control-label. View output in Full screen.

.form-horizontal .control-label {
  text-align: left !important; /* !important added for priority in SO snippet. */
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<form accept-charset="UTF-8" action="/task_categories/1" class="form-horizontal" id="edit_task_category_1" method="post">
  <div class="row">
    <div class="col-md-4">
      <div class="well">
        <div class="form-group">
          <label class="control-label col-sm-6" for="task_category_task_category_users_attributes_0_Enable">Enable?</label>
          <div class="col-sm-6">
            <input name="task_category[task_category_users_attributes][0][enable]" type="hidden" value="0">
            <input class="form-control" id="task_category_task_category_users_attributes_0_enable" name="task_category[task_category_users_attributes][0][enable]" type="checkbox" value="true">
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-6" for="task_category_task_category_users_attributes_0_Enable Comment">Enable comment?</label>
          <div class="col-sm-6">
            <input name="task_category[task_category_users_attributes][0][comments_enabled]" type="hidden" value="0">
            <input class="form-control" id="task_category_task_category_users_attributes_0_comments_enabled" name="task_category[task_category_users_attributes][0][comments_enabled]" type="checkbox" value="true">
          </div>
        </div>
        <input id="task_category_task_category_users_attributes_0_user_id" name="task_category[task_category_users_attributes][0][user_id]" type="hidden" value="1">
      </div>
    </div>

    <div class="col-md-4">
      <div class="well">
        <div class="form-group">
          <label class="control-label col-sm-6" for="task_category_task_category_users_attributes_1_Enable">Enable?</label>
          <div class="col-sm-6">
            <input name="task_category[task_category_users_attributes][1][enable]" type="hidden" value="0">
            <input class="form-control" id="task_category_task_category_users_attributes_1_enable" name="task_category[task_category_users_attributes][1][enable]" type="checkbox" value="true">
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-6" for="task_category_task_category_users_attributes_1_Enable Comment">Enable comment?</label>
          <div class="col-sm-6">
            <input name="task_category[task_category_users_attributes][1][comments_enabled]" type="hidden" value="0">
            <input class="form-control" id="task_category_task_category_users_attributes_1_comments_enabled" name="task_category[task_category_users_attributes][1][comments_enabled]" type="checkbox" value="true">
          </div>
        </div>
        <input id="task_category_task_category_users_attributes_1_user_id" name="task_category[task_category_users_attributes][1][user_id]" type="hidden" value="2">
      </div>
    </div>
  </div>
</form>
like image 22
m4n0 Avatar answered Jan 03 '23 20:01

m4n0