Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place a non editable percentage sign within a HTML input field

Tags:

html

css

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;
}
like image 453
alex johnson Avatar asked Nov 30 '16 10:11

alex johnson


People also ask

How do you make an input tag not editable in HTML?

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).

How do you make an input value not editable?

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.

How do I add a currency symbol to the input field?

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.


3 Answers

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>
like image 135
Rajshekar Reddy Avatar answered Sep 27 '22 22:09

Rajshekar Reddy


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>
like image 25
Pete Avatar answered Sep 27 '22 22:09

Pete


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.

like image 23
Pedro Alvares Avatar answered Sep 27 '22 21:09

Pedro Alvares