I am using Bootstrap-Vue to build a form, and I would like the placeholder text to animate so that it sits on top of the input using CSS Transitions.
I currently have this bit of code which is generated by Bootstrap-Vue:
<form class="form" _lpchecked="1">
<div role="group" class="form-group">
<label for="year" class="d-block form-control-placeholder">Year</label>
<div>
<input id="year" name="year" type="text" class="form-control">
</div>
</div>
</form>
I can't change the above markup as Bootstrap-Vue uses components for inputs and form groups which generate the markup for me. Therefore other similar questions asked on StackOverflow don't answer my question.
As for my CSS, it looks like this:
.form-group {
position: relative;
margin-bottom: 1.5rem;
}
.form-control-placeholder {
position: absolute;
top: 0;
padding: 7px 0 0 13px;
transition: all 200ms;
opacity: 0.5;
color: red;
}
.form-control:focus + .form-control-placeholder,
.form-control:valid + .form-control-placeholder {
font-size: 75%;
transform: translate3d(0, -100%, 0);
opacity: 1;
}
The Codepen for the above code is here: https://codepen.io/Canvasandcode/pen/OJJZLmM