当输入div聚焦时显示div

use*_*313 0 html css focus css-selectors css3

我想在输入字段聚焦时显示div(活动?)在下面的代码中,我想显示.text何时.input聚焦.我正在尝试这个:

HTML:

<div class="box">
    <input class="input" type="text" value="" />
    <div class="text">text</div>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.text { display: none; }   
.input:focus .text { display: block; }
Run Code Online (Sandbox Code Playgroud)

示例:

的jsfiddle

And*_*ndy 5

您需要使用兄弟CSS选择器:

.input:focus + .text{
    display: block;
}
Run Code Online (Sandbox Code Playgroud)

更新小提琴