Unable to set textarea width with CSS

前端 未结 8 1719
梦谈多话
梦谈多话 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/

    0 讨论(0)
  • 2021-02-07 00:47

    Set width 100% and then use max-width:

         textarea { 
              width:100%;
              max-width:250px;
         }
    

    // removed margin and padding, you can add it if you want.

    0 讨论(0)
提交回复
热议问题