Input placeholder
How do I make sure that the placeholder is not hidden when entering the input?
input,select,textarea{
border-radius: 4px;
border: 1px solid #DCECF4;
color: #81819F;
font-family: 'Rubik';
font-weight: 400;
font-size: 14px;
padding: 0 15px;
}
input,select{
height: 40px;
}
input.field::placeholder {
font-size: 16px;
color: #81819F;
transition: 0.3s;
opacity: 1;
}
input.field:focus::placeholder {
transform: translateY(-18px);
font-size: 14px;
}
<input type="text" class="field" name="email" value="" placeholder="Email">
<input type="text" class="field" name="password" value="" placeholder="Пароль">
0
2 answers
There placeholder
is encrypted - ideally it can be a regular span as in my example
body {
padding: 30px;
}
div {
display: inline-block;
position: relative;
}
div span {
position: absolute;
top: 0;
transition: 0.2s;
}
input:focus~span {
transform: translateY(-18px);
font-size: 14px;
color: red;
}
<div>
<input type="text">
<span>слово</span>
</div>
2
Author: MaximLensky, 2019-07-28 16:22:32
document.addEventListener('keyup', () => {
let target = event.target;
if (target.tagName == 'INPUT' && target.classList.contains('input')) {
if (target.value.length > 0) {
target.classList.add('filled');
} else {
target.classList.remove('filled');
}
}
});
form {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
padding: 30px;
max-width: 300px;
}
.label {
position: relative;
display: block;
height: 48px;
cursor: text;
}
.label input {
position: absolute;
bottom: 0;
border: 0;
height: 2px;
width: 100%;
padding: 0 0 0 35px;
transition: all 0.3s ease;
vertical-align: bottom;
font-size: 16px;
box-sizing: border-box;
border-bottom: 2px solid rgb(185, 42, 36);
color: rgb(185, 42, 36);
}
.label input:focus,
.label input.filled {
height: 100%;
width: 100%;
background: white;
box-shadow: 0 1px 3px #aaaaaa;
border: 2px solid @mainColor;
outline: none;
}
.label input:focus+label,
.label input.filled+label {
position: absolute;
transform: translateY(-34px);
font-size: 12px;
color: #8f0222;
}
.label input+label {
color: #8f0222;
line-height: 48px;
padding-left: 3px;
transform: translateY(0);
transition: all 0.3s ease;
pointer-events: none;
}
.mail {
margin-top: 0;
margin-bottom: 35px;
}
<form action="POST">
<div class="start">
<label class="label mail" for="emailEnter">
<input class="input" type="email" id="emailEnter" required="required"/>
<label for="emailEnter">E-mail</label>
</label>
<label class="label" for="passwordEnter">
<input class="input" type="password" id="passwordEnter" minlength="5" required="required"/>
<label for="passwordEnter">Пароль</label>
</label>
</div>
</form>
Example from my site
1
Author: Владислав, 2019-07-27 14:34:27