I currently have a number of inputs like this:
<input type="number" id="milliseconds">
This input field is used to represent a value in milliseconds. I do however have multiple number inputs which take a value in dB or percentages.
<input type="number" id="decibel">
<input type="number" id="percentages">
What I would like to do is add a type suffix to the input field to let users know what kind of value the input represents. Something like this:
(This image is edited to show what result I want to have,I hid the up and down arrows from the input type as well).
I have tried to Google this but I can't seem to find anything about it. Does anyone know if this is possible, and how you can accomplish something like this?
Another interesting approach would be to use a little of JavaScript in order to make suffix actually stick to the input text (which probably looks better):
However, this is just a proof of concept. You will need to work on it a little further to make it production-ready, e.g. make it a reusable plugin.
Also, you will need to handle a case, where input element is getting overflowed.
If you have option to add elements to input then you can try this:-
You can use a wrapper
<div>
for each input element and position the unit as a pseudo element::after
with thecontent
of your corresponding units.This approach works well for the absolute positioned pseudo elements will not effect the existing layouts. Nevertheless, the downside of this approach is, that you have to make sure, that the user input is not as long as the text field, otherwise the unit will be unpleasantly shown above. For a fixed user input length, it should work fine.