I want to use Tobias Ahlin's script to style up my input-box. But while it's perfectly working on paragraphs, on inputs doesn't. Also, the ::before doesn't show up in the spectator.
Here's my code:
.edit input {
text-decoration: none;
outline: none;
border: none;
position: relative;
font-size: 1.125rem;
}
.edit input::before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: #000;
visibility: hidden;
transform: scaleX(0);
transition: all 0.15s ease-in-out 0s;
}
.edit input:active::before, .edit input:focus::before {
visibility: visible;
transform: scaleX(1);
}
<div class="edit">
<input type="text" maxlength="15" value="Some content here...">
</div>
I'm using it in an Angular 5 application, but I don't think it's relevant right now.
The problem is that input and other form elements don't render :before and :after pseudo elements.
Authors specify the style and location of generated content with the :before and :after pseudo-elements. As their names indicate, the :before and :after pseudo-elements specify the location of content before and after an element's document tree content. The 'content' property, in conjunction with these pseudo-elements, specifies what is inserted.
W3 Specs
So wrapping the input in a span would make this to work:
<div class="edit">
<span><input type="text" maxlength="15" value="Some content here..."></span>
</div>
CSS ... please note for .edit span::before bottom: -2px difference than your code.
span {
position: relative;
}
.edit input {
text-decoration: none;
outline: none;
border: none;
position: relative;
font-size: 1.125rem;
}
.edit span::before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: -2px;
left: 0;
background-color: #000;
visibility: hidden;
transform: scaleX(0);
transition: all 0.15s ease-in-out 0s;
}
.edit span:hover::before {
visibility: visible;
transform: scaleX(1);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With