I have an html input.
The input has padding: 5px 10px;
I want it to be 100% of the parent div's width(which is fluid).
However using width: 100%;
causes the input to be 100% + 20px
how can I get around this?
I have an html input.
The input has padding: 5px 10px;
I want it to be 100% of the parent div's width(which is fluid).
However using width: 100%;
causes the input to be 100% + 20px
how can I get around this?
Use padding in percentages too and remove from the width:
Just understand the difference between width:auto; and width:100%; Width:auto; will (AUTO)MATICALLY calculate the width in order to fit the exact given with of the wrapping div including the padding. Width 100% expands the width and adds the padding.
You can do it without using
box-sizing
and not clear solutions likewidth~=99%
.Demo on jsFiddle:
padding
andborder
margin
=border-width
+horizontal padding
padding
equal tomargin
from previous stepHTML markup:
CSS:
This is why we have
box-sizing
in CSS.I’ve edited your example, and now it works in Safari, Chrome, Firefox, and Opera. Check it out: http://jsfiddle.net/mathias/Bupr3/ All I added was this:
Unfortunately older browsers such as IE7 do not support this. If you’re looking for a solution that works in old IEs, check out the other answers.
Here is the recommendation from codeontrack.com, which has good solution examples:
You can do this: