爲什麼電子郵件和密碼寬度超出input-container
寬度?CSS輸入元素寬度超出容器
form {
background: #ccc;
}
.input-container {
background: red;
width: 469px;
margin: 0 auto;
}
.usermail,
.userpword {
margin-top: 10px;
}
input,
button {
width: 100%;
border-radius: 6px;
border: 1px solid #cacece;
padding: 10px 12px;
font-size: 1em;
}
.username input {
width: 206px;
}
<form action='' method='post' id='signupform'>
<div class='input-container'>
<div class='username'>
<input type='text' name='fname' id='fname' placeholder='First Name'>
<input type='text' name='lname' id='lname' placeholder='Last Name'>
</div>
<div class='usermail'>
<input type='email' name='email' id='email' placeholder='Email'>
</div>
<div class='userpword'>
<input type='password' name='pword' id='pword' placeholder='Password'>
</div>
<button>Sign Up</button>
</div>
</form>
因爲你填充不計入寬度算,所以你的輸入是'100%+填充'寬。使用'box-sizing:border-box'來解決這個問題。此外,同樣適用於您的邊框。 – somethinghere
[寬度爲100%的CSS輸入超出父級限制]的可能重複(http://stackoverflow.com/questions/16907518/css-input-with-width-100-goes-outside-parents-bound) – showdev
^谷歌「CSS盒子模型」 –