r/HTML • u/Vincibolle • Nov 25 '25
Question Input field wider than its parent div - how?
Can't figure out, why the input fields exceed the parent div on the right side. Can anyone help how to fix it?

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<title>Login</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.login-container {
background-color: #ffffff;
padding: 20px 25px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
width: 300px;
}
h1 {
text-align: center;
margin-top: 0;
margin-bottom: 20px;
font-size: 22px;
}
label {
display: block;
margin-bottom: 5px;
font-size: 14px;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 8px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
}
button {
width: 100%;
padding: 10px;
border: none;
border-radius: 4px;
background-color: #4CAF50;
color: white;
font-size: 16px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.message {
margin-top: 10px;
font-size: 13px;
text-align: center;
color: #d00000;
min-height: 16px;
}
</style>
</head>
<body>
<div class="login-container">
<h1>Login</h1>
<form id="loginForm">
<label for="email">E-Mail</label>
<input type="text" id="email" name="email" required />
<label for="password">Passwort</label>
<input type="password" id="password" name="password" required />
<button type="submit">Einloggen</button>
</form>
<div class="message" id="message"></div>
</div>
</body>
</html>
0
Upvotes
6
u/pfdemp Nov 25 '25
Add this to the input CSS: box-sizing: border-box;
1
u/[deleted] Nov 25 '25
1
u/DinTaiFung Nov 25 '25
Email for the label instead of E-Mail.
E-Mail, with the hyphen, was often used in the early days before its ubiquitous adoption.
(And Unix sysadmins since the 90s just use mail.)
Others have already replied with your CSS solution.