Reputation: 477
How to make textarea/input that has left/right padding 10px and will be as wide as its parent.
textarea,input{
padding:5px 10px 5px 10px;
width:100%;
}
In that case input is wider.
Upvotes: 4
Views: 3134
Reputation: 19803
You can check my answer in related question
HTML markup:
<div class="input_wrap">
<input type="text" />
</div>
CSS:
div {
padding: 6px 10px; /* equal to negative input's margin for mimic normal `div` box-sizing */
}
input {
width: 100%; /* force to expand to container's width */
padding: 5px 10px;
border: none;
margin: 0 -10px; /* negative margin = border-width + horizontal padding */
}
Upvotes: 1
Reputation: 56429
Ah, the good old Box Model. Padding is ADDED to the width, so in order to achieve the desired effect, you'd have to use percentages in padding also. Try this:
textarea, input {
padding: 1% 2% 1% 2%;
width: 96%;
}
Upvotes: 3