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

前端 未结 14 1680
别那么骄傲
别那么骄傲 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:11

    Width value doesn't take into account border or padding:

    http://www.htmldog.com/reference/cssproperties/width/

    You get 2px of padding in each side, plus 1px of border in each side.
    100% + 2*(2px +1px) = 100% + 6px, which is more than the 100% child-content the parent td has.

    You have the option of:

    • Either setting box-sizing: border-box; as per @pricco's answer;
    • Or using 0 margin and padding (avoiding the extra size).

提交回复
热议问题