html如何实现tab效果,纯CSS实现Tab切换标签效果代码

在线演示地址遇新是直朋能到分览如下:

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

CSS_Tab简洁版

body{margin:0; font-size:12px; background:#666;}

#box{width:400px; height:300px; margin:100px auto 0;}

#tab_nav{margin:0; padding:0; height:25px; line-height:24px;}

#tab_nav li{float:left; margin:0 3px; list-style:none; border:1px solid #999; border-bottom:none; height:24px; width:60px; text-align:center; background:#FFF;}

a{font:bold 14px/24px "微软雅黑", Verdana, Arial, Helvetica, sans-serif; color:green; text-decoration:none;}

a:hover{color:red;}

#tab_content{width:398px; height:273px; border:1px solid #999; font:bold 4em/273px "微软雅黑", Verdana, Arial, Helvetica, sans-serif; text-align:center; background:#FFF; overflow:hidden;}

#t_1,#t_2,#t_3{width:100%; height:273px;}

tab_壹
tab_贰
tab_叁

本文来源于网络:查看 >https://www.cnblogs.com/Porsche911/p/7099338.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用以下代码实现tab标签切换HTML代码: ```html <div class="tab"> <button class="tablinks" onclick="openTab(event, 'tab1')">标签1</button> <button class="tablinks" onclick="openTab(event, 'tab2')">标签2</button> <button class="tablinks" onclick="openTab(event, 'tab3')">标签3</button> </div> <div id="tab1" class="tabcontent"> <p>这是标签1的内容。</p> </div> <div id="tab2" class="tabcontent"> <p>这是标签2的内容。</p> </div> <div id="tab3" class="tabcontent"> <p>这是标签3的内容。</p> </div> ``` CSS代码: ```css .tab { overflow: hidden; border: 1px solid #ccc; background-color: #f1f1f1; } .tab button { background-color: inherit; float: left; border: none; outline: none; cursor: pointer; padding: 14px 16px; transition: 0.3s; } .tab button:hover { background-color: #ddd; } .tab button.active { background-color: #ccc; } .tabcontent { display: none; padding: 6px 12px; border: 1px solid #ccc; border-top: none; } .tabcontent.show { display: block; } ``` JavaScript代码: ```javascript function openTab(evt, tabName) { var i, tabcontent, tablinks; tabcontent = document.getElementsByClassName("tabcontent"); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].classList.remove("show"); } tablinks = document.getElementsByClassName("tablinks"); for (i = 0; i < tablinks.length; i++) { tablinks[i].classList.remove("active"); } document.getElementById(tabName).classList.add("show"); evt.currentTarget.classList.add("active"); } ``` 在JavaScript代码中,openTab()函数会根据传入的参数tabName来显示相应的标签页,并将对应的按钮设为激活状态。同时,如果有其他标签页处于激活状态,会将其隐藏并将对应的按钮设为非激活状态。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值