4

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.

user1785870
  • 477
  • 1
  • 6
  • 16
  • A good discussion about solving this with box-sizing is available here: http://css-tricks.com/box-sizing/ (This is the solution Meliborn suggests, note what browsers it is compatible with. It's at the bottom of the article) – C. E. Nov 22 '12 at 22:15

4 Answers4

6
    textarea{
        box-sizing: border-box;
        width:100%;
        padding: 10px
    }
Meliborn
  • 6,495
  • 6
  • 34
  • 53
3

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%;
}
Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
1

You can check my answer in related question

Demo on jsFiddle:
enter image description here

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 */ 
}
Community
  • 1
  • 1
Vladimir Starkov
  • 19,264
  • 8
  • 60
  • 114
0

Add margin property to your css code.

SaidbakR
  • 13,303
  • 20
  • 101
  • 195
  • 2
    This has to do with the box model adding padding to the width. So the width will be 100%+padding width. Please motivate why your solution will work. – C. E. Nov 22 '12 at 22:11