admin管理员组

文章数量:1355721

I am trying to set the width of a text input field as a percentage of total page width, as follows:

<input type="text" id="url" NAME="otherSite" size="70%" value=""/>

This doesn't seem to work. It seems I can specify the width of an input field only in absolute terms.

Short of going to javascript, is there any simple way? I am trying to have it look good both on desktop and mobile, where the windows are likely to be of very different size.

I am trying to set the width of a text input field as a percentage of total page width, as follows:

<input type="text" id="url" NAME="otherSite" size="70%" value=""/>

This doesn't seem to work. It seems I can specify the width of an input field only in absolute terms.

Short of going to javascript, is there any simple way? I am trying to have it look good both on desktop and mobile, where the windows are likely to be of very different size.

Share Improve this question asked Jul 20, 2011 at 2:20 LucaLuca 1,0681 gold badge11 silver badges17 bronze badges 1
  • Possible duplicate of Can the size of input fields be set to percent values? – Vadzim Commented May 28, 2017 at 18:37
Add a ment  | 

1 Answer 1

Reset to default 6

Use the style attribute:

<input type="text" id="url" NAME="otherSite" style="width:70%" value=""/>

You also might want to read up on CSS (Cascading Style Sheets).

本文标签: javascriptHow to set the width of a text input field in a form to a percentage of page widthStack Overflow