I currently have a series of input field boxes which are numerical based. The trouble I am having is adding a '%' symbol at the end of each box. Ultimately i want the % symbol to be non editable to the user however unsure how to go about it. Any ideas would be beneficial
HTML
<div class="ModifiedValues">
<span class="valuePadding"><center><b>New Value</b></center></span>
<span class="valuePadding"><input type="number" max="100" accuracy="2" min="0" id="inputRRPDiscount" style="text-align:left;"><br></span>
<span class="valuePadding"><input type="number" max="100" accuracy="2" min="0" id="inputMargin" style="text-align:left;"><br></span>
<span class="valuePadding"><input type="number" max="100" accuracy="2" min="0" id="inputMarkUp" style="text-align:left;"><br></span>
<span class="valuePadding"><input type="number" max="100" accuracy="2" min="0" id="inputSalesDiscount" style="text-align:left;"><br></span>
</div>
CSS
.ModifiedValues {
position: absolute;
left: 250px;
top: 28px;
color: #666;
font-size: 12px;
width: 85px;
}
.valuePadding {
padding:5px 5px 5px 5px;
display:block;
}
The readonly attribute is a boolean attribute. When present, it specifies that an input field is read-only. A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).
The second way of making the input text non-editable is using the CSS pointer-events property set to "none", which will stop the pointer-events.
To achieve this, we need to wrap a textbox inside a div tag. We then need to set the position of the div to relative position. Then, we can add a span HTML tag with a currency sign inside the div tag and set the position of the label to an absolute position against the div tag.
Here you go
.valuePadding {
border: 1px inset #ccc;
}
.valuePadding input {
border: none;
padding:0px;
outline: none;
}
<span class="valuePadding"><input type="number" max="100" accuracy="2" min="0" id="inputRRPDiscount" style="text-align:left;">%</span>
<br>
I would style your spans to look like your inputs and then remove the styles from the input. You can then use the after
psuedo selector to add the percentage:
.input-holder {
border: 1px solid #cccccc;
display: inline-block;
padding: 5px;
}
.input-holder > input {
border: 0;
margin: 0;
padding: 0;
outline:none;
}
.input-holder:after {
content: '%';
}
<div class="ModifiedValues">
<span class="valuePadding"><center><b>New Value</b></center></span>
<span class="valuePadding input-holder"><input type="number" max="100" accuracy="2" min="0" id="inputRRPDiscount" style="text-align:left;"></span>
<br>
<span class="valuePadding input-holder"><input type="number" max="100" accuracy="2" min="0" id="inputMargin" style="text-align:left;"></span>
<br>
<span class="valuePadding input-holder"><input type="number" max="100" accuracy="2" min="0" id="inputMarkUp" style="text-align:left;"></span>
<br>
<span class="valuePadding input-holder"><input type="number" max="100" accuracy="2" min="0" id="inputSalesDiscount" style="text-align:left;"></span>
<br>
</div>
Assuming that you're going to put these elements within a relative positioned div, you could handle it this way:
HTML:
<div class="col-md-6">
<span id="percent-sign">%</span>
<input type="number" min="0" max="100">
</div>
CSS:
<style>
#percent-sign {
top: 8px;
left: 45px;
color: #555;
position: absolute;
z-index: 1;
}
</style>
Notice that I'm using Bootstrap grid classes (col-md-6), which already gave that div relative positioning. If that's not your case, set relative positioning to your div.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With