<div class="field" data-field>
<input type="text" class="field__input" data-field-input placeholder="0">
<div class="field__overlay" >
<div class="field__value" data-field-value="$"></div>
</div>
</div>
<div class="field" data-field>
<input type="text" class="field__input" data-field-input placeholder="0">
<div class="field__overlay" >
<div class="field__value" data-field-value="$"></div>
</div>
</div>
body {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 30px;
min-height: 100vh;
rgb(255, 255, 255)
font-family: arial;
}
::-webkit-input-placeholder {
color:#999;
opacity:1
}
:-moz-placeholder,
::-moz-placeholder {
color:#999;
opacity:1
}
:-ms-input-placeholder {
color:#999;
opacity:1
}
:focus::-webkit-input-placeholder {
color:transparent;
}
:focus:-moz-placeholder,
:focus::-moz-placeholder {
color:transparent;
}
:focus:-ms-input-placeholder {
color:transparent;
}
input {
box-sizing: border-box;
transition: none;
width: 300px;
height: 2.8125rem;
border-radius: 0.75rem;
padding: 0.1875rem 0.625rem;
color: #4e3831;
font-size: 1rem;
line-height: 1rem;
font-weight: 400;
text-align: center;
outline: none;
box-shadow: none;
min-width: 0;
background-color: #e5e2e2;
border: 1px solid transparent;
background: linear-gradient(#e5e2e2, #e5e2e2 0) padding-box,
linear-gradient(90deg, #fa5560, #4d91ff) border-box;
letter-spacing: 1px;
font-family: arial;
}
input:focus {
background: linear-gradient(#ececec, #ececec 0) padding-box, linear-gradient(90deg, #ff2aac, #8b00ff) border-box;
}
.field {
position: relative;
z-index: 0;
}
.field__overlay {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
pointer-events: none;
font-family: arial;
}
.field__value {
position: relative;
z-index: 0;
/* color: transparent; */
font-size: 1rem;
line-height: 1rem;
font-weight: 400;
letter-spacing: 1px;
}
.field__value:after {
content: attr(data-field-value);
position: absolute;
left: calc(100% + 0.3em);
top: 50%;
transform: translateY(-50%);
color: blue;
font-size: 1.3rem;
margin-top: -0.02em;
}
const fields = document.querySelectorAll('[data-field]');
for (const field of fields) {
console.log(field);
const input = field.querySelector('[data-field-input]');
const value = field.querySelector('[data-field-value]');
input.addEventListener("input", (event) => {
value.textContent = event.target.value;
});
};
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.