Form Alignment in bootstrap 3

Bill

I have the following HTML in bootstrap 3 that gives the following display: enter image description here

The HTML it as follows.

In one row i have only one field, while on others I have 3. Is it possible with bootstrap to make all rows position "first" label on the same position? In this case, "Project Name", "Location", and "Project Value" will be aligned same position.

Thanks

<div class="container">
    <div class="row" id="mainForm">
         <form class="form-horizontal">
                <div class="row">
                    <div class="form-group col-xs-12 col-sm-6">
                        <label for="txtProjectName" class="control-label col-sm-4 col-xs-3">Project Name</label>
                        <div class="col-sm-8 col-xs-9">
                            <input type="text" class="form-control" id="txtProjectName" placeholder="Name of Project">
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group col-xs-12 col-sm-6">
                        <label for="txtLocation" class="control-label col-sm-4 col-xs-3">Location</label>
                        <div class="col-sm-8 col-xs-9">
                            <input type="text" class="form-control" id="txtLocation" placeholder="Location">
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group col-xs-12 col-sm-4">
                        <label for="txtProjectValue" class="control-label col-sm-4 col-xs-3">Project Value</label>
                        <div class="col-sm-8 col-xs-9">
                            <input type="text" class="form-control" id="txtprojectValueUsd" placeholder="Project Value (US $)">
                        </div>
                    </div>
                    <div class="form-group col-xs-12 col-sm-4">
                        <label for="txtCCCValue" class="control-label col-sm-4 col-xs-3">CCC Value</label>
                        <div class="col-sm-8 col-xs-9">
                            <input type="text" class="form-control" id="txtCCCValue" placeholder="CCC Value (US $)">
                        </div>
                    </div>
                    <div class="form-group col-xs-12 col-sm-4">
                        <label for="txtProjectValueLocal" class="control-label col-sm-4 col-xs-3">Project Value Local</label>
                        <div class="col-sm-8 col-xs-9">
                            <input type="text" class="form-control" id="txtProjectValueLocal" placeholder="Project Value Local Currency">
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-xs-offset-2 col-xs-10">
                        <button type="submit" class="btn btn-primary">Login</button>
                    </div>
                </div>
            </form>
    </div>
    <div class="row top-buffer">
    </div>
</div>
Tasos K.

In the first two div.row you the .form-group with .col-sm-6. If you change it to .col-sm-4 you will get the alignment you want.

E.g.:

<div class="col-xs-12 col-sm-4">
    <div class="form-group">
        <label for="txtProjectName" class="control-label col-sm-4 col-xs-3">Project Name</label>
        <div class="col-sm-8 col-xs-9">
        <input type="text" class="form-control" id="txtProjectName" placeholder="Name of Project">
        </div>        
    </div>
</div>

Here is a working demo http://jsfiddle.net/wmyuj7gy/.

EDIT:

If you want the first two rows to be full width you need to change the .col-sm-4 to .col-sm-12 and the inner elements to have the .col-sm-1 and .col-sm-11 class.

Also, you should nt use the .form-group class in the same div with the .col-sm-* classes because is messes with the grid's paddings.

Here is a fixed example of your code, with also some other changes in the last row to make the form perfectly aligned http://jsfiddle.net/wmyuj7gy/3/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related