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 widt
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 this:
width: auto;
padding: 20px;
What about wrapping it in a container. Container shoud have style like:
{
width:100%;
border: 10px solid transparent;
}
Use padding in percentages too and remove from the width:
padding: 5%; width: 90%;
Use css calc()
Super simple and awesome.
input {
width: -moz-calc(100% - 15px);
width: -webkit-calc(100% - 15px);
width: calc(100% - 15px);
}
As seen here: Div width 100% minus fixed amount of pixels
By webvitaly (https://stackoverflow.com/users/713523/webvitaly)
Original source: http://web-profile.com.ua/css/dev/css-width-100prc-minus-100px/
Just copied this over here, because I almost missed it in the other thread.
For me, using margin:15px;padding:10px 0 15px 23px;width:100%
, the result was this:
The solution for me was to use width:auto
instead of width:100%
. My new code was:
margin:15px;padding:10px 0 15px 23px;width:auto
. Then the element aligned properly: