Reputation: 580
Please tell me how right align this form "Log in" button using bootstrap. I tired to use pull-right class. But after resizing my button is not in the correct position.
<div role="form">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control"/>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control"/>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Remember Me
</label>
</div>
<button class="btn-info btn">Log in</button>
</div>
Upvotes: 28
Views: 101890
Reputation: 22663
You can use text-right
first you have to wrap it in a div
like this:
<div class="text-right">
<button class="btn-info btn">Log in</button>
</div>
Here is the full code
<div role="form">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control"/>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control"/>
</div>
<div class="checkbox">
<label>
<input type="checkbox"/> Remember Me
</label>
</div>
<div class="text-right"> <!--You can add col-lg-12 if you want -->
<button class="btn-info btn">Log in</button>
</div>
</div>
Upvotes: 68
Reputation: 19152
If you are inside a container with rows and columns in Bootstrap4, all the floats don't work properly.
Instead you have to add a spacer column to get things to align.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<p>Float right demo inside a container-fluid, Bootstrap 4</p>
<div class="container-fluid">
<div class="row">
<div class="col bg-warning"></div><!-- This is the filler column -->
<div class="col-auto bg-success">.col-auto (Like a Float Right)</div>
</div>
</div>
Hope that helps.
Upvotes: 0