I’m trying to create my website to show my work, and I’m creating a "Contact Me" form. Now, I’m focusing on the aspect of it. I made a design of what it should look like, but last time I worked with HTML and CSS was like 8 years ago.
Here is the design:
The design
Here is the actual result:
The result right now
/* ---------- Footer ---------- */
#contact {
margin: 10vh auto;
max-width: 1800px;
width: 90%;
padding: 2%;
border-radius: 10px;
}
.contact-highlight {
font-size: 1.5em;
}
.form-element {
display: flex;
flex-direction: column;
align-items: center;
}
.form-component {
font-family: Poppins, Arial, Helvetica, sans-serif;
border-radius: 5px;
border: none;
background-color: #DAD8DD;
color: #0D0221;
width: 25vw;
height: 5vh;
}
.form-text-area {
font-family: Poppins, Arial, Helvetica, sans-serif;
border-radius: 5px;
border: none;
background-color: #DAD8DD;
color: #0D0221;
width: 25vw;
height: 20vh;
}
.form-submit {
font-family: Poppins, Arial, Helvetica, sans-serif;
border-radius: 10px;
border: none;
background-color: #F50056;
color: #ffffff;
font-size: 1em;
width: 10vw;
height: 5vh;
}
.footer-text {
color: #ffffff;
text-align: center;
}
<!-- The page's footer. -->
<footer>
<!-- The contact infos. -->
<div id="contact" class="white-section">
<!-- Contact text. -->
<p class="highlight contact-highlight">Si vous aimez mes travaux ou souhaitez simplement me contacter,</p>
<p>vous pouvez remplir ce formulaire. Je vous répondrais aussi vite que possible !</p>
<!-- Contact form. -->
<form class="form-element" action="php/contact.php" method="post">
<p>Prénom-Nom<em class="highlight">*</em></p>
<input class="form-component" type="text" name="name" autocomplete="off" required>
<p>Email<em class="highlight">*</em></p>
<input class="form-component" type="email" name="email" autocomplete="off" required>
<p>Objet<em class="highlight">*</em></p>
<input class="form-component" type="text" name="subject" autocomplete="off" required>
<p>Message<em class="highlight">*</em></p>
<textarea class="form-text-area" name="message" autocomplete="off" required></textarea>
<input class="form-submit" type="submit" value="Send">
</form>
</div>
<!-- Footer credits. -->
<p class="footer-text">© Basset Etienne | All rights reserved.</p>
</footer>
I already used "CSS grid" to create the Projects part, and I understand how "display: flex" works, but I don’t know how to approach this problem. I tried to check online for a way to put elements in a certain order, but I’m afraid it would be a pain to put it responsive.
2
Answers
I would do like this:
Inside the form put a div to be a flexbox container, then put two other divs, one for the name, email and object fields and the other for the message field
display: grid
is what you need.By observation, we can see that our grid have four rows and two columns, as visualized below (not to scale):
This can be translated to HTML and CSS as (simplified for ease of explanation):
The message box lies on the second column and span 3 rows, while the submit field span both columns. We specify that in our CSS as well:
Try it: