How to make a textbox and a textarea same width cross-browsers?

前端 未结 8 1552
孤街浪徒
孤街浪徒 2021-02-19 22:23

Setting the width of both the textbox (ie. input type=\"text\") and the textarea to 500px doesn\'t work in IE6 and Chrome, only works fine in FF2 (haven\'t tested other browsers

8条回答
  •  南方客
    南方客 (楼主)
    2021-02-19 23:15

    I have been experimenting and found out that "the ratio" between text input and textarea can be calculated using 21 * 8*x.

    If you have

    < input type="text" size="X" />< br/> < textarea cols="X">< /textarea>

    ... and you want them to be equally wide, use this formula to calculate the width for the input text.

    if x = 70 then 21*8*70 = 581px

    So you will write:

    < input type="text" size="70" style="width: 581px" />< br/> < textarea cols="70">< /textarea>

    The two will become equal!

    In this way in a program/website/etc you can enter the same value and get the same result (cols in textarea)!

提交回复
热议问题