Reputation: 1985
I want to display a div when an input field is focused(active?)
In the following code, I want to display .text
when .input
is focused.
I'm trying this:
HTML :
<div class="box">
<input class="input" type="text" value="" />
<div class="text">text</div>
</div>
CSS :
.text { display: none; }
.input:focus .text { display: block; }
Example :
Upvotes: 0
Views: 154
Reputation: 44581
You can also use general sibling selector ~
:
.input:focus ~ .text { display: block; }
Upvotes: 1
Reputation: 4778
You need to use the sibling CSS selector:
.input:focus + .text{
display: block;
}
Upvotes: 5