方法一、利用a标签的锚点实现tab切换
(推荐教程:CSS教程)
代码如下:
- nbsp;html>
cssTab切换2 *{ margin: 0; padding: 0; text-decoration: none; } .tab{ width: 300px; height: 300px; margin: 30px auto; overflow: hidden; } .nav{ height: 30px } .content{ height: 270px; overflow: hidden; } .cont{ height: 270px; } #the1{ background: green; } #the2{ background: blue; }
登录后复制
(学习视频推荐:CSS教程)
立即学习“前端免费学习笔记(深入)”;
方法二、利用radio按钮和:checked选择器
代码如下:
- nbsp;html>
纯css实现tab切换 *{ margin: 0; padding: 0; } .tab{ width: 300px; height: 150px; margin-left: 30px; margin-top: 30px; border: 1px solid #eee; position: relative; overflow: hidden; } input[type='radio']{ display: none; } .tab label{ display: block; cursor: pointer; position: absolute; width: 60px; height: 30px; line-height: 30px; text-align: center; border: 1px solid #eee; } .label-1{ left: 0; top: 0; } .label-2{ left: 60px; top: 0; } input[type='radio']:checked~div[class^='mod']{ display: block; } input[type='radio']:checked~label{ background: orange; } [class^='mod']{ position: absolute; top: 40px; left: 20px; display: none; }
- 275万购昌平邻铁三居
- 总价20万买一居
- 200万内购五环三居
- 北京首现零首付楼盘
- 新中式的酷色温情
- 深圳房价大跌,每平8W
- 800万买沙井三房
- 宝安房价平均900W
登录后复制
以上就是css如何实现Tab切换的详细内容,更多请关注【创想鸟】其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。