Sometimes we need to make an input component whose width changes with the input text, such as the tag input box below:
My content is editable
|
|
At this time, regular input seems a bit difficult because the width of input is fixed.
According to the above code, we can find that this effect is achieved by an element that cannot be input. The secret lies in the last attribute contenteditable="true"
in style. This attribute can turn the element into an editable text box, but it will not be displayed, so it looks like an ordinary div.
Using this attribute reasonably, we can achieve many interesting effects. Make our development efficiency twice as good with half the effort.