I would like to have a text input field containing the "$" sign in the very beginning, and no matter what editing occurs to the field, for the sign to be persistent.
I would be good if only numbers were accepted for input, but that's just a fancy addition.
If you only need to support Safari, you can do it like this:
and an input field like
<input class="currency" data-symbol="€" type="number" value="12.9">
This way you don't need an extra tag and keep the symbol information in the markup.
Another solution which I prefer is to use an additional input element for an image of the currency symbol. Here's an example using an image of a magnifying glass within a search text field:
html:
css:
This results in the input on the left sidebar here:
https://fsfe.org
None of these answers really help if you are concerned with aligning the left border with other text fields on an input form.
I'd recommend positioning the dollar sign absolutely to the left about -10px or left 5px (depending whether you want it inside or outside the input box). The inside solution requires direction:rtl on the input css.
You could also add padding to the input to avoid the direction:rtl, but that will alter the width of the input container to not match the other containers of the same width.
or
https://i.imgur.com/ajrU0T9.png
Example: https://plnkr.co/edit/yshyuRMd06K1cuN9tFDv?p=preview
For bootstrap its works
Don't use class="form-control" in input field.
Since you can't do
::before
withcontent: '$'
on inputs and adding an absolutely positioned element adds extra html - I like do to a background SVG inline css.It goes something like this:
It outputs the following:
Note: the code must all be on a single line. Support is pretty good in modern browsers, but be sure to test.