HTML definiert die Struktur eines Formulars. CSS ist zuständig für Layout, Abstände, Farben und Benutzererlebnis.
div oder p.
Ohne CSS wirken Formulare technisch und unübersichtlich. Mit CSS werden sie benutzerfreundlich und visuell klar.
<form class="login-form">
<div class="field">
<label>Benutzername</label>
<input type="text">
</div>
</form>
.field {
margin-bottom: 1rem;
}
input-Felder lassen sich über Rahmen, Farben und Größen anpassen.
input {
width: 100%;
padding: 0.5rem;
border: 1px solid #ccc;
border-radius: 4px;
}
:focus – Feld ist aktiv:hover – Maus darüberinput:focus {
border-color: #2b7cff;
outline: none;
}
button {
background: #2b7cff;
color: white;
padding: 0.6rem 1.2rem;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #1f5fd1;
}
.login-form {
max-width: 400px;
margin: 2rem auto;
}
input:required {
border-left: 4px solid #ff9800;
}
input:invalid {
border-color: red;
}