Appending Text Suffixes to Number Inputs
In a typical scenario, number inputs like convey a value in milliseconds. However, with multiple number inputs indicating values in dB or percentages, it becomes necessary to differentiate these values visually. Adding a text suffix clarifies the type of value represented.
Solution:
Utilize a wrapper
Implementation:
<code class="css">/* Prepare wrapper element */ div { display: inline-block; position: relative; } /* Position the unit to the right */ div::after { position: absolute; top: 2px; right: .5em; transition: all .05s ease-in-out; } /* Adjust unit position on hover and focus */ div:hover::after, div:focus-within::after { right: 1.5em; } /* Override for Firefox (arrows always shown) */ @supports (-moz-appearance:none) { div::after { right: 1.5em; } } /* Specify abbreviation for each unit class */ .ms::after { content: 'ms'; } .db::after { content: 'db'; } .percent::after { content: '%'; }</code>
<code class="html"><div class="ms"> <input type="number" id="milliseconds"> </div> <hr> <div class="db"> <input type="number" id="decibel"> </div> <hr> <div class="percent"> <input type="number" id="percentages"> </div></code>
The above is the detailed content of How to Add Text Suffixes to Number Inputs for Visual Differentiation?. For more information, please follow other related articles on the PHP Chinese website!