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">
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With