HTML input textbox with a width of 100% overflows table cells

前端 未结 14 1716
别那么骄傲
别那么骄傲 2021-01-29 20:28

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,

14条回答
  •  死守一世寂寞
    2021-01-29 21:18

    The problem with things like width:95%; is that they don't look right in wide flexible layouts (because 5% can then be like 30 pixels).

    The following solutions works very well for me (tested in Firefox, IE 9, Safari):

    (added the colors to make it easier to notice the correct padding)

    The trick is to wrap the input with two divs, the outer has a 3px margin (which makes it 3px smaller than the td), the inner has a 3px padding. This makes the input 6px smaller than the td, which is what you wanted to begin with.

    I am not sure about the mechanics of this, but it works.

    In this simple example, it also works with just a single div with right margin 6. However, in the case of my web application, only the above solution works.

提交回复
热议问题