How can I add padding to a textarea without causing the width to increase?

后端 未结 4 1362
谎友^
谎友^ 2021-02-05 06:58

I\'ve been having trouble setting a textarea element\'s width and using padding via CSS. The padding value seems to change the width of the textarea, which I\'d rather it not do

4条回答
  •  遥遥无期
    2021-02-05 07:07

    The CSS box model defines "width" as the width of the content, excluding border, padding and margin.

    Fortunately, CSS3 has a new box-sizing property that lets you modify this behaviour to instead include padding etc. in the specified width using:

    box-sizing: border-box;
    

    According to the link above, most modern browsers (including IE >= 8) support this property, but they have different names in each browser.

提交回复
热议问题