<label class="box">
<input type="text" class="box__input" placeholder=" ">
<box class="box__content">Это <span class="color-red">подсказка</span></box>
</label>
<label class="box">
<input type="text" class="box__input" placeholder=" ">
<box class="box__content">Это <span class="color-red">подсказка</span> 2</box>
</label>
body {
padding: 0;
margin: 0;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
font-size: 25px;
}
.color-red {
color: red;
}
.box {
display: inline-block;
position: relative;
z-index: 0;
overflow: hidden;
margin: 10px;
}
.box__input {
background-color: yellow;
border: 1px solid #000;
height: 50px;
box-sizing: border-box;
padding: 0 20px;
color: #000;
width: 300px;
font-size: 20px;
}
.box__content {
box-sizing: border-box;
padding: 0 20px;
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%) translateX(0);
opacity: 0.8;
pointer-events: none;
color: #000;
transition: 0.3s all;
}
.box__input:focus ~ .box__content,
.box__input:not(:placeholder-shown) ~ .box__content {
transform: translateY(-50%) translateX(100%);
opacity: 0;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.