Reputation: 39
i have a React code that is doing simple form:
return (
<form onSubmit={handleSubmit} className="login-form">
<label>
Username:
<input
type="text"
value={username}
onChange={(event) => setUsername(event.target.value)}
className="input"
/>
</label>
<br />
<label>
Password:
<input
type="password"
value={password}
onChange={(event) => setPassword(event.target.value)}
className="input"
/>
</label>
<br />
<button type="submit" className="button">Login</button>
</form>
The fact is when i'm styling this code i get the witdh button is greater than inputs but i don't understand what i'm doing bad, because its giving 100% width in both elements.
body {
margin: 0;
padding: 0;
font-family: sans-serif;
background-color: #f1f1f1;
}
.login-form {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
padding: 20px;
flex-direction: column;
background-color: white;
box-shadow: 0 0 10px 3px rgba(0, 0, 0, 0.1);
}
.label {
font-size: 18px;
font-weight: bold;
margin-bottom: 5px;
}
.input {
padding: 10px;
font-size: 18px;
border: 1px solid #ddd;
display: block;
margin-bottom: 10px;
width: 100%;
}
.button {
padding: 10px 20px;
font-size: 18px;
background-color: #4caf50;
color: white;
border: none;
cursor: pointer;
width: 100%;
}
So, what i'm doing wrong? I thought the button width 100% would have been adapt to class form
Upvotes: 0
Views: 29
Reputation: 1417
body {
margin: 0;
padding: 0;
font-family: sans-serif;
background-color: #f1f1f1;
display: flex;
justify-content: center;
}
.login-form {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
padding: 20px;
flex-direction: column;
background-color: white;
box-shadow: 0 0 10px 3px rgba(0, 0, 0, 0.1);
width: min-content;
}
.label {
font-size: 18px;
font-weight: bold;
margin-bottom: 5px;
}
.input {
padding: 10px;
font-size: 18px;
border: 1px solid #ddd;
display: block;
margin-bottom: 10px;
}
.button {
padding: 10px 20px;
font-size: 18px;
background-color: #4caf50;
color: white;
border: none;
cursor: pointer;
width: 100%;
}
<form onSubmit={handleSubmit} class="login-form">
<label>Username:
<input type="text"
class="input"/>
</label>
<br />
<label>Password:
<input type="password"
class="input"/>
</label>
<br />
<button type="submit" class="button">Login</button>
</form>
Upvotes: 1