Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place dollar symbol inside a text input

I want to keep dollar symbol at beginning of text box. I am able to achieve this using the below code.

It works find in chrome and IE. The dollar symbol goes and sits next to label in firefox. How do i fix this problem? And for aligning the dollar symbol inline with text i use top 2px. Is there a way to better the css code.

.input-symbol-dollar:after {
  color: #37424a !important;
  content: "$";
  font-size: 16px !important;
  font-weight: 400;
  left: 10px;
  position: absolute;
  top: 2px;
}

.input-symbol-dollar {
  position: relative;
}

.abc-input {
  border: 2px solid #c9c9c9;
  box-shadow: none;
  color: #6b6f72;
  font-size: 0.9375rem;
  text-transform: none;
  width: 100%;
  color: #37424a !important;
  font-family: "Roboto Regular", sans-serif;
  font-size: 16px !important;
  font-weight: 400;
  height: 42px !important;
  padding-left: 17px !important;
  display: inline-block !important;
}

label {
  color: #37424a;
  display: inline-block;
  font-family: "Roboto Bold", sans-serif;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 8px;
}
<label for="abcInput" class="abc-label">lable filed </label>
<span class="input-symbol-dollar">
<input  type="text" id="abcInput" tabindex="0" name="abc" class="abc-input "  placeholder="0.00"></span>

https://jsfiddle.net/8jdek3zt/5/

like image 812
Hacker Avatar asked Oct 16 '25 17:10

Hacker


1 Answers

It looks like there's a lot of unnecessary code in your example.

Here's a simplified version that works on Chrome, Firefox and IE (not tested in Safari).

span {
  display: inline-block;
  position: relative;
}

input {
  border: 2px solid #c9c9c9;
  box-shadow: none;
  font-family: "Roboto Regular", sans-serif;
  font-size: 1.5em;
  height: 42px;
  padding-left: 20px;
}

span::before {
  content: "$";
  font-family: "Roboto Regular", sans-serif;
  font-size: 1.5em;
  position: absolute;
  left: 5px;
  top: 50%;
  transform: translateY(-50%);
}
<span>
<input placeholder="0.00">
</span>

Here's an explanation of the vertical centering method for the pseudo-element:

  • Element will not stay centered, especially when re-sizing screen
like image 156
Michael Benjamin Avatar answered Oct 18 '25 11:10

Michael Benjamin