tags:

views:

21

answers:

3

I have a text input inside a <td> that has a padding of 5px; When setting its width to 100% it comes out of the boundaries of the <td> for 10px. Is there a way to make it fill the entire <td> (i.e. in practice its width should become 100% - 10px) without using JavaScript?

Thanks in advance

A: 

Check the width you specified for your column . Probably that might causing the problem.

Multiplexer
A: 

If you change it to display: block it will expand to fill up the parent's width.

John Sheehan
Sounded like a good approach compared to my answer so I tried it real quick, going block style is causing the text input to "take up the entire line" but visually the width of the input box doesn't expand to fill the td.My Test was: <table width="200px" border="1"> <tr> <td width="200px"> <input type="text" style="padding:5px; display: block;">Test </td> </tr> </table> The word Test does get sent to a new line in the td, but the input box width didn't fill.
ManiacZX
A: 

See http://www.w3schools.com/css/css_boxmodel.asp

It doesn't sound as if that will work as the css width is content only and the padding is in addition to.

So if you are specifying the content to 100% and the padding is 5px, then the total is 100% + 5px.

It sounds as if you really don't need the padding in this situation as it is the only element in the td, so I might consider overriding the inherited padding value on the element, at least the left and right such as:

<input type="text" style="width:100%; padding-left:0px; padding-right:0px;"/>

Another approach would be to use a slightly smaller percentage such as 95% or 90%.

ManiacZX