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

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

    The problem is due to the input element box model. I just recently found a nice solution to the issue when trying to keep my input at 100% for mobile devices.

    Wrap your input with another element, a div for example. Then apply the styling you want for your input to that the wrapper div. For example:

    .input-wrapper { border-raius:5px; padding:10px; } .input-wrapper input[type=text] { width:100%; font-size:16px; }

    Give .input-wrapper rounded corner padding etc, whatever you want for your input, then give the input width 100%. You have your input padded nicely with a border etc but without the annoying overflow!

提交回复
热议问题