I’m putting up a simple form that consists of two input fields for text and one textarea, and I want everything to be aligned perfectly, all three items below each other. Of course I want them to be equally wide, but no matter what I do, the textarea still shows up a bit wider on the right side.
Any ideas?
Here’s what I have:
form {
display: flex;
flex-direction: column;
max-width: 60%;
}
.form-groep {
display: flex;
flex-direction: row;
}
label {
margin-bottom: 1rem;
width: 20vw;
font-size: 1.3vw;
}
input, textarea {
padding: 8px;
font-size: 0.8rem;
border: 1px solid #ccc;
border-radius: 6px;
width: 40vw;
margin: 0;
}
textarea {
resize: none;
height: 10vw;
box-sizing: border-box;
}
I tried changing every possible parameter I could think of, this is the best I could get after many attempts.
Upon request, here’s my HTML code as well:
<form action="contactformulier.php" method="post">
<div class="form-groep">
<label for="naam">Naam *</label>
<input type="text" id="naam" name="naam" tabindex="1" required>
</div>
<div class="form-groep">
<label for="email">E-mailadres *</label>
<input type="email" id="email" name="email" tabindex="2" required>
</div>
<div class="form-groep">
<label for="bericht">Bericht *</label>
<textarea id="bericht" name="bericht" tabindex="3" required></textarea>
</div>
<input type="submit" value="Verzend" tabindex="4"/>
</form>
2
Answers
Spelling of ‘form-groep’ appears to be wrong. Is it ‘form-group’?
If it is correct, then please paste the HTML code too.
I would recommend first setting up a global style to "reset" the box-sizing.
of course this is an opinionated solution, but this ensures your styles have more consistency.
Take padding and margin in consideration as well, also the display value can affect how elements calculate width and height, for example
label
is "display: inline" by default, while other elements may have "block" or "inline-block" and may react different to the styles of width and height.