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?
box-sizing: border-box
is a quick, easy way to fix it:This will work in all modern browsers, and IE8+.
Here's a demo: http://jsfiddle.net/thirtydot/QkmSk/301/
The browser prefixed versions (
-webkit-box-sizing
, etc.) are not needed in modern browsers.What about wrapping it in a container. Container shoud have style like:
I had the same issue. Fix it like so:
Cheers
You can try some positioning tricks. You can put the input in a div with
position: relative
and a fixed height, then on the input haveposition: absolute; left: 0; right: 0;
, and any padding you like.Live example
Move the input box' padding to a wrapper element.
See example here: http://jsfiddle.net/L7wYD/1/
Try this: