html - Make an <input> look like normal text in a paragraph -


take code here:

<p>lorem ipsum <input type="text" value="algo" /> dolor sit ...</p> 

sample: http://codepen.io/dbugger/pen/krampx

how can make input totally normal text, inside paragraph? set display: inline width seems still fixed.

elements inherit default values browsers. need "reset" of them in order make input element appear surrounding text:

p input {   border: none;   display: inline;   font-family: inherit;   font-size: inherit;   padding: none;   width: auto; } 

this close can css alone. if want variable width, have resort js instead of css, adjusting element it's value way beyond scope of css. modifying elements after fact, based on user input or changes due just-in-time effects, js/jquery used for.

note depending on browser you're using (and due possibility future browsers might things radically different nowadays' practices), list not exhaustive.


the way can "fake" effect in clean manner without js use element contenteditable attribute, (unlike input element) store user input in content of element instead of it's value. example of technique, see this answer

though while won't need js effect, need retrieve content of element. use past can imagine if you're providing printable document never needs programmatically handle input or store it.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -