Radio button show/hide content

时光毁灭记忆、已成空白 提交于 2019-12-06 09:56:46

Place label tags after both in the input tags. Like below

<input type=radio id="show" name="group">
<input checked type=radio id="hide" name="group">
<label id="id1" for="show"><span id="id1">show</span></label>
<label id="id2" for="hide"><span id="id2">hide</span></label> 
<span id="content">Content</span>

Add these css rules to existing rules

input#show:checked ~ label#id1{
  display:none;
}
input#show:checked ~ label#id2{
   display:block;
}

input#hide:checked ~ label#id2{
   display:none;
}
input#hide:checked ~ label#id1{
   display:block;
}

demo http://jsfiddle.net/vtfqW/1/

If you want make content toggle. Menu toggle example.

input#toogle-content {
  display:none;
}
label#toogle-content div{
   background:silver;
}
span#content {
  display:none;
  background:#333;
  color:#fff;
}
input#toogle-content:checked ~ span#content{
  display:block;
}
<input type="checkbox" id="toogle-content">
<label for="toogle-content" id="toogle-content"><div>Menu</div></label>
<span id="content">Home<br>Marks<br>Other</span>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!