Unable to set textarea width with CSS

前端 未结 8 1718
梦谈多话
梦谈多话 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:21

    Maybe you have a user specific css overlay defined somewhere in your browser, because i just tested it and it works as expected: http://jsbin.com/exase/edit (Tested on windows. Maybe Apple native widgets have some quirk?)

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

    This is probably caused by different default margins on the <input> and <textarea> elements. Try using something like this.

    input[type="text"], textarea { 
        padding: 0;
        margin: 0;
        width:250px; 
    }
    
    0 讨论(0)
  • 2021-02-07 00:29

    Try border:0; or border: 1px solid #000;

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

    This answer is three years late, but I'm posting it here just in case anyone else is trying to set the width in em's and not pixels and comes across this post (as I just did). Make sure the font-size is the same,

    e.g.

    input, textarea {
        font-size:12px; 
        width:20em; 
        padding:0; 
        margin:0 
    }
    

    otherwise the textarea may be a different size (true on FF12).

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

    you may use:

    input[type="text"], textarea { 
        -moz-box-sizing: border-box;
        -ms-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
    }
    
    0 讨论(0)
  • 2021-02-07 00:42

    I was struggling with this kind of problem too, and this question was the first result of my googling. What finally worked for me was setting box-sizing: content-box for the textarea - Drupal 7 defaults this to border-box which causes the padding and border width to be subtracted from the size of the textarea.

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