Reputation: 253
I have a form to that collects contact and payment information. I have the form mostly completed, but for the additional space on the right side of the form. I would like to have left and right edges of the form have the same amount of spacing.
Here is my bootstrap code
<main class="form-tenant-register">
<form method="post">
<div class="row g-5">
<div class="col-9">
<h4 class="mb-3">Contact Info</h4>
<div class="row g-3">
<div class="col-sm-4">
<label for="firstName" class="form-label">First name</label>
<input type="text" class="form-control" id="firstName" placeholder="" value="" required="">
<div class="invalid-feedback">
Valid first name is required.
</div>
</div>
<div class="col-sm-6">
<label for="lastName" class="form-label">Last name</label>
<input type="text" class="form-control" id="lastName" placeholder="" value="" required="">
<div class="invalid-feedback">
Valid last name is required.
</div>
</div>
<div class="col-5">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" placeholder="[email protected]">
<div class="invalid-feedback">
Please enter a valid email address for updates.
</div>
</div>
<div class="col-5">
<label for="phone" class="form-label">Phone</label>
<input class="form-control" id="phone">
<div class="invalid-feedback">
Please enter a valid phone number.
</div>
</div>
</div>
<div class="col-10">
<hr class="my-4">
</div>
<h4 class="mb-3">Payment Info</h4>
<div class="row gy-3">
<div class="col-md-3">
<input id="credit" name="paymentMethod" type="radio" class="form-check-input" checked="" required="">
<label class="form-check-label" for="credit">Credit card</label>
</div>
<div class="col-md-3">
<input id="debit" name="paymentMethod" type="radio" class="form-check-input" required="">
<label class="form-check-label" for="debit">Debit card</label>
</div>
<div class="col-md-3">
<input id="paypal" name="paymentMethod" type="radio" class="form-check-input" required="">
<label class="form-check-label" for="paypal">PayPal</label>
</div>
</div>
<br />
<div class="row g-3">
<div class="col-sm-10">
<label for="cc-name" class="form-label">Full name on card</label>
<input type="text" class="form-control" id="cc-name" placeholder="" required="">
<div class="invalid-feedback">
Name on card is required
</div>
</div>
<div class="col-sm-4">
<label for="cc-number" class="form-label">Credit card number</label>
<input type="text" class="form-control" id="cc-number" placeholder="" required="">
<div class="invalid-feedback">
Credit card number is required
</div>
</div>
<div class="col-sm-2">
<label for="cc-expiration" class="form-label">Expiration</label>
<input type="text" class="form-control" id="cc-expiration" placeholder="" required="">
<div class="invalid-feedback">
Expiration date required
</div>
</div>
<div class="col-sm-2">
<label for="cc-cvv" class="form-label">CCV</label>
<input type="text" class="form-control" id="cc-cvv" placeholder="" required="">
<div class="invalid-feedback">
Security code required
</div>
</div>
<div class="col-sm-2">
<label for="zip" class="form-label">Zip</label>
<input type="text" class="form-control" id="zip" placeholder="" required="">
<div class="invalid-feedback">
Zip code required.
</div>
</div>
</div>
<div class="col-10">
<hr class="my-4">
</div>
<div class="col-10">
<button class="w-100 btn btn-primary btn-lg" type="submit">Sign up</button>
</div>
</div>
</div>
</form>
</main>
Here is some additional info from my site.css
.form-tenant-register {
padding: 15px;
margin:auto;
}
.form-tenant-register form {
margin-bottom: 15px;
background: #f7f7f7;
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
padding: 30px;
}
Any help would be kindly appreciated.
Upvotes: 0
Views: 72
Reputation: 126
From what I understand you want to centralize the form contents inside the form container(the lightgray box).
Since bootstrap rows are flex container, you can easily do this by adding class justify-content-center
to the main row div, so it becomes like this:
<main class="form-tenant-register">
<form method="post">
<div class="row g-5 justify-content-center">
<div class="col-9">
(... rest of html)
You might notice that adding the class to only this row will do for a mobile view but it won't be totally centralized in desktops - that's because you have other children rows where their contents do not occupy all the 12 bootstrap columns so their own content won't be centralized. You need to add this class to those rows as well, but that might make the title decentralized, so you'll have to adjust that as well.
Upvotes: 1