js+css实现滑动切换切换div的不同显示

本文介绍了一个使用HTML和CSS实现的简洁Tab菜单切换效果,通过简单的鼠标悬停事件,可以轻松地在不同的内容面板间进行切换。该效果适用于网页设计中的多内容展示,能够提升用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

先看效果(没有被破坏的源码,只需要改动即可实现你的功能)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<title>简洁Tab</title>
<style type="text/css">
<!--
body,div,ul,li{
 padding:0;
 text-align:center;
}
body{
 font:12px "宋体";
 text-align:center;
 margin-top: 12px;
 margin-bottom: 12px;
}
a:link{
color:#00F;
text-decoration:none;
}
a:visited {
color: #00F;
text-decoration:none;
}
a:hover {
color: #c00;
text-decoration:underline;
}
ul{ list-style:none;}

#Tab1{
width:100%;
margin:0px;
padding:0px;
margin:0 auto;
background:#0F6}

.Menubox {
width:100%;
background:#666;
height:50px;
line-height:28px;
margin:auto;
}
.Menubox ul{
margin:0px;
padding:0px;
/*可以居中显示*/
display:table;
margin:10px auto;

}
.Menubox li{
float:left;
display:block;
cursor:pointer;
width:114px;
text-align:center;
color:#949694;
font-weight:bold;
}
.Menubox li.hover{
padding:0px;
background:#fff;
width:116px;
border-left:1px solid #A8C29F;
border-top:1px solid #A8C29F;
border-right:1px solid #A8C29F;
background:url(http://www.hxcgw.com/bbs/upfile/200792994426548.gif);
color:#739242;
font-weight:bold;
height:27px;
line-height:27px;
}
/*用于下部显示内容*/
.Contentbox{
clear:both;
margin-top:0px;
border:1px solid #A8C29F;
border-top:none;
height:181px;
text-align:center;
padding-top:8px;
}
.STYLE2 {font-size: 18px}
-->
</style>
<script>
<!--
/*第一种形式 第二种形式 更换显示样式*/
function setTab(name,cursel,n){
for(i=1;i<=n;i++){
 var menu=document.getElementById(name+i);
 var con=document.getElementById("con_"+name+"_"+i);
 menu.className=i==cursel?"hover":"";
 con.style.display=i==cursel?"block":"none";
}
}
//-->
</script>
</head>
<body>
<br><br>
<div id="Tab1">
    <div class="Menubox">
        <ul>
         <li id="one1" onmouseover="setTab('one',1,3)" class="hover"> <font id="hide1">一号在哪里</font> </li>
        
         <li id="one2" onmouseover="setTab('one',2,3)" ><font id="hide2" >2号在哪里</font></li>
        
         <li id="one3" onmouseover="setTab('one',3,3)"><font  id="hide3">3号在哪里</li>
        
        </ul>
    </div>
    
    <div class="Contentbox"> 
         <div id="con_one_1" class="hover">
         我是一号    
         
         </div>


         <div id="con_one_2" style="display:none">
        我是二号
         </div>
         
         <div id="con_one_3" style="display:none"> 
         我是三号
         </div>
         
    </div>
</div>
<br>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值