Utilizing the calc property in a solution, I am facing challenges when trying to calculate the percentage width of an element with margins, padding, and borders set in pixels.
Take a look at this demo:
#form {
margin: 200px auto;
width: 360px;
background:green;
padding:0
}
input[type="text"], input[type="password"] {
width: calc(50% - 42px);
margin: 10px;
padding: 10px;
border: solid 1px #000;
}
The form contains two inputs, and I aim for them to completely fill their parent div. My formula is:
100%= (input_width + ( margin_width + padding_width + border_width ) * 2 ) * 2
=> input_width= 50% - 42px
However, currently, the maximum width I can use is 50% - 45px to keep both inputs on the same line. What am I missing? http://jsfiddle.net/uL2syf4m/3/