html css div显示隐藏,在不使用jQuery的HTML和CSS中单击时显示隐藏div

3f74b20d36b5059f66209e017e3ffc6f.png

MMMHUHU

使用label和checkbox输入使所选项目保持打开状态并切换。.collapse{  cursor: pointer;  display: block;  background: #cdf;}.collapse + input{  display: none; /* hide the checkboxes */}.collapse + input + div{  display:none;}.collapse + input:checked + div{  display:block;}Collapse 1 

Content 1
Collapse 2
Content 2
使用label和命名radio输入与复选框类似,它仅关闭已打开的复选框。在两个输入上使用name="c1" type="radio"。.collapse{  cursor: pointer;  display: block;  background: #cdf;}.collapse + input{  display: none; /* hide the checkboxes */}.collapse + input + div{  display:none;}.collapse + input:checked + div{  display:block;}Collapse 1 
Content 1
Collapse 2
Content 2
使用tabindex和:focus与radio输入类似,您还可以使用Tab键触发状态。在手风琴外部单击将关闭所有打开的项目。.collapse > a{  background: #cdf;  cursor: pointer;  display: block;}.collapse:focus{  outline: none;}.collapse > div{  display: none;}.collapse:focus div{  display: block; }
  Collapse 1 
Content 1....
  Collapse 2 
Content 2....
使用 :target与使用radio输入类似,您还可以使用Tab和⏎键进行操作.collapse a{  display: block;  background: #cdf;}.collapse > div{  display:none;}.collapse > div:target{  display:block; }
  Collapse 1 
Content 1....
  Collapse 2 
Content 2....
使用和标记(纯HTML)您可以使用HTML5的detail和summary标签来解决此问题,而无需任何CSS样式或Javascript。请注意,Internet Explorer(或Microsoft Edge)不支持这些标签。  Collapse 1 

Content 1...

  Collapse 2 

Content 2...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值