Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrease width of input in HTML

Tags:

html

css

So I have an input tag in HTML, and I need to decrease its width to (let's just say) 80% of its normal width. I've tried setting width:80% but that didn't work. I would prefer solutions using only HTML/CSS, but I'm open to anything. My Google searches came up with results to change the width to a fixed amount like 50 pixels, not relative to its normal width. Thanks!

<input id="myInput" type="text">
like image 485
aryanm Avatar asked Nov 19 '25 21:11

aryanm


1 Answers

First, get the current input width (myInputWidth). Multiply it by some factor (0.8). Then modify the width.

var myInputWidth = (document.getElementById("myInput").offsetWidth);

document.getElementById("myInput").style.width = myInputWidth * 0.8 + "px";

You can check out an example of this here.

like image 121
Edwin Avatar answered Nov 22 '25 10:11

Edwin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!