Does anyone know why the input elements with a width of 100% go over the table\'s cells border.
In the simple example below input box go over the table\'s cells border,
I usually set the width of my inputs to 99% to fix this:
input {
width: 99%;
}
You can also remove the default styles, but that will make it less obvious that it is a text box. However, I will show the code for that anyway:
input {
width: 100%;
border-width: 0;
margin: 0;
padding: 0;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
Ad@m
instead of this margin struggle just do
input{
width:100%;
background:transparent !important;
}
this way the cell border is visible and you can control row background color
Take out the "http://www.w3.org/TR/html4/loose.dtd" from the DOCTYPE declaration and it fix your problem.
Cheers! :)
I know that this question is 3 years old but the problem still persists for current browsers and folks are still coming here. The solution for now is calc():
input {
width: calc(100% - 12px); /* IE 9,10 , Chrome, Firefox */
width: -webkit-calc(100% - 12px); /*For safari 6.0*/
}
It is supported by most modern browsers.
I solved the problem by applying box-sizing:border-box
; to the table cells themselves, besides doing the same with the input and the wrapper.
The problem lies in border-width
of input element.
Shortly, try setting the margin-left
of the input element to -2px
.
table input {
margin-left: -2px;
}