Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to line up labels and read-only fields in a Bootstrap 2 form

In bootstrap 2, what's the recommended way of lining up labels and read-only text fields in a form. The following code sample creates misaligned fields:

<form class="form-horizontal">
    <fieldset>
        <legend>Sample</legend>    
        <div class="control-group">
            <label class="control-label">Readonly Field</label>
            <div class="controls">
                Lorem Ipsum and then some
            </div>
        </div>
    </fieldset>
</form>

Note that I can fix this up myself with custom CSS. That's not the issue. It just seems silly that this is not build-in so I feel like I must be overlooking something.

like image 421
batkuip Avatar asked Mar 27 '12 10:03

batkuip


People also ask

How do I center align a label in bootstrap?

Add text-align: center in your CSS or text-center class to your parent element (probably to a row or container ).

How do I add a space between label and textbox in bootstrap?

using . form-group{ margin-bottom: 20px;} works, but best to use bootstrap's builtin and put .

How do I customize Bootstrap form?

The customized form can be created by using Bootstrap 4 like checkbox, radio buttons, file inputs and more. Bootstrap simplifies the process of alignment and styling of web pages in many forms like label, input, field, textarea, button, checkbox, etc. Custom Checkbox: The . custom-control and .


2 Answers

You can use the uneditable input

<span class="input-xlarge uneditable-input">Lorem Ipsum and then some</span>

EDIT:

As of bootstrap 3.0 a class has been added to handle this

When you need to place regular, static text next to a form label within a horizontal form, use the .form-control-static class on a <p>

<div class="controls">
  <p class="form-control-static">Lorem Ipsum and then some</p>
</div>
like image 104
chris vdp Avatar answered Oct 12 '22 17:10

chris vdp


There is a hack. You can use <label> with class "checkbox"

In your case:

<div class="controls">
 <label class="checkbox">
     Lorem Ipsum and then some
 </label>
</div>
like image 3
XuDing Avatar answered Oct 12 '22 16:10

XuDing