Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force input element's width to size to its content/value

I'm trying to unstyle an input element so that its text looks like plain/inline-text, and I've reset pretty much every css property it can have, but I can't get the input's width to adjust/shrink to its content (input { width:auto; min-width:0; } does not work). It obeys an arbitrary width like input { width: 10px; }, so obviously its width is adjustable.

I see people trying to do it with javascript (the fiddle from the answer doesn't work anymore), so I'm wondering if what I want is even possible.

Here's a fiddle.

like image 561
Jakob Jingleheimer Avatar asked Feb 15 '13 22:02

Jakob Jingleheimer


1 Answers

Played with this. Couldn't do it. What are you trying to achieve? Are you aware of the contenteditable attribute?

This might get you what you need.

https://developer.mozilla.org/en-US/docs/HTML/Content_Editable

like image 153
Kevin Boucher Avatar answered Oct 29 '22 03:10

Kevin Boucher