css如何实现Tab切换

css如何实现Tab切换

方法一、利用a标签的锚点实现tab切换

(推荐教程:CSS教程)

代码如下:

  1. nbsp;html>    <span class="pln">cssTab</span><span class="pun">切换</span><span class="lit">2</span>     *{ 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; }
        
            ONE        TWO    
        
            
    第一张
            
    第二张
        

登录后复制

(学习视频推荐:CSS教程)

立即学习“前端免费学习笔记(深入)”;

方法二、利用radio按钮和:checked选择器

代码如下:

  1. nbsp;html>    <span class="pun">纯</span><span class="pln">css</span><span class="pun">实现</span><span class="pln">tab</span><span class="pun">切换</span>     *{ 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切换的详细内容,更多请关注【创想鸟】其它相关文章!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

点点赞赏,手留余香

给TA打赏
共0人
还没有人赞赏,快来当第一个赞赏的人吧!
    编程技术

    如何利用css画出一个三角形

    2025-3-10 20:33:27

    编程技术

    书写CSS样式有哪三种方式

    2025-3-10 20:33:36

    0 条回复 A文章作者 M管理员
    欢迎您,新朋友,感谢参与互动!
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    私信列表
    搜索