Basically, what I want to do is display the :before
of the parent span when the input is focused. This is my code.
HTML:
<span>
<input type="text" placeholder="Some text here" />
<p>Error will be shown here.</p>
</span>
And CSS:
input[type=text]:focus + span:before{
display: inline-block;
position: absolute;
content: "";
width: 200px;
height: 30px;
background-color: #000;
border: 1px solid #f00;
top: 0;
left: 0;
}
But this won't work. The :before
is never displayed. Maybe there is something I'm not doing right. Any help will be appreciated.
This question is not a duplicate of Is there a CSS parent selector?, in that I'm not trying to select the parent. I'm selecting the :before
of the parent. Doing something like span > input:focus
works but span:before > input:focus
does not work.