Luca
Luca

Reputation: 1068

How to set the width of a text input field in a form to a percentage of page width?

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.

Upvotes: 1

Views: 11266

Answers (1)

rsbarro
rsbarro

Reputation: 27369

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).

Upvotes: 6

Related Questions