3 回答
TA贡献1966条经验 获得超4个赞
你甚至可以创建一个标签系统,无需任何JavaScript在所有使用单选按钮的CSS技巧。
如果选中了单选按钮,则使用同级选择器:显示下一个 div ~。
input{
display: none;
}
label{
display: inline-block;
padding: 3px;
border: 1px solid #aaa;
}
label:hover{
cursor: pointer;
}
.display{
display: none;
}
[type=radio]:checked ~ .display{
display: block;
}
<section>
<label for="div1">Show div 1</label>
<label for="div2">Show div 2</label>
<label for="div3">Show div 3</label>
</section>
<section>
<input type="radio" id="div1" name="tab-nav" checked />
<div class="display">
Text from div 1.
</div>
</section>
<section>
<input type="radio" id="div2" name="tab-nav" />
<div class="display">
Text from div 2. It's cool.
</div>
</section>
<section>
<input type="radio" id="div3" name="tab-nav" />
<div class="display">
Text from div 3. Definitely a cool css trick.
</div>
</section>
添加回答
举报