I have successfully designed a contact form using a CSS grid layout that features 4 input fields and a submit button spanning across 2 columns.
Two of the input fields take up 1fr of space each, while the remaining two are 1/3 wide. My challenge lies in centering the submit button below the input fields as per my figma design screenshot.
After scouring through various responses on stack overflow, it seems that I need to create a div container within the form that covers all columns (1/3 in this case) to properly position the button using justify-content: center. Although I followed these suggestions, I'm still unable to achieve the desired outcome.
Is there anyone who can point out where I might be making an error?
/* Homepage Contact Form */
.container-form {
max-width: 120rem;
margin: 0 auto;
padding: 0 1.5rem;
padding-bottom: 2rem;
}
.homepage-contact {
align-items: center;
justify-content: center;
text-align: center;
max-width: 70rem;
padding-top: 13rem;
}
.contact-message {
font-size: 1.8rem;
margin-bottom: 2rem;
font-family: 'Raleway', sans-serif;
line-height: 3rem;
}
.home-contact-form form {
display: grid;
grid-template-columns: 1fr 1fr;
margin: 0 auto;
max-width: 90rem;
}
.home-contact-form form p {
margin: 0.8rem;
}
.home-contact-form form .full {
grid-column: 1 / 3;
}
.contact-btn-container {
grid-column: 1/ 3;
justify-content: center;
}
.home-contact-form form input {
height: 4rem;
}
.home-contact-form form input,
.home-contact-form form textarea,
home-contact-form {
width: 100%;
}
input {
padding-left: 1.5rem;
}
textarea {
padding-left: 1.5rem;
}
<!-- Homepage contact start -->
<section class="homepage-contact container-form">
<div class="homepage-contact-text">
<h2 class="title contact-title">Lets Discuss Your Project</h2>
<p class="contact-message">We’re always happy to discuss your project with you and put together a free proposal, just fill out the form below or give us a call to get started</p>
</div>
</section>
<div class="home-contact-container">
<div class="home-contact-form">
<form action="">
<p class="full">
<input type="text" name="name" placeholder="Name">
</p>
<p>
<input type="email" name="email" placeholder="Email">
</p>
<p>
<input type="text" name="phone" placeholder="Phone">
</p>
<p class="full">
<textarea name="message" placeholder="Message" rows="15"></textarea>
</p>
<div class="contact-btn-container">
<p>
<button class="contact-btn">Submit</button>
</p>
</div>
</form>
</div>
</div>