Unable to set textarea width with CSS

前端 未结 8 1724
梦谈多话
梦谈多话 2021-02-07 00:00

I have attempted to use this CSS to set the width of my form elements:

input[type=\"text\"], textarea { width:250px; }

If you look at this Fire

8条回答
  •  野的像风
    2021-02-07 00:45

    Try removing padding and borders. Or try making them the same for both elements

    input[type="text"],
    textarea {
        width:250px;
        padding: 3px;
        border: none;
        }
    

    Or:

    input[type="text"],
    textarea {
        width:250px;
        padding: 0;
        border: 1px solid #ccc;
        }
    

    INPUT and TEXTAREA elements often have some padding applied by the browser (varies by browser) and this can make things appear effectively wider than the assigned width.

    UPDATE: also box-sizing: border-box; is a handy way to set widths that that padding and border will eat into rather than add onto. See: http://www.paulirish.com/2012/box-sizing-border-box-ftw/

提交回复
热议问题