鼠标悬浮 html中的tabs

html中制作标签卡(tabs)

快速建立一个html标签卡(tabs)

 

在网页中常常会看到这样的标签页,其实实现的方法也不难,接下来就介绍如何快速的建立一个html标签卡

 

 

这是我做好的demo预览效果

 

使用的软件以及技术:

  1. sublime text 3编辑器
  2. css3
  3. jQuery

 

1.建立一个html,并写好基本的结构

如果你使用的是sublime text 3的并安装emmet插件,就可以快速创建了:div>(ul>li{Section $}*4)+div*4,然后敲击tab键。

给整体的div添加class为label,给第一个li添加class为showed,给第一个小div添加class为showed,并完善div里的文字内容

 


 
 
  1. <div class="label">
  2. <ul>
  3. <li class="showed">Section 1 </li>
  4. <li>Section 2 </li>
  5. <li>Section 3 </li>
  6. <li>Section 4 </li>
  7. </ul>
  8. <div class="showed"> <h3>This is the first section </h3> </div>
  9. <div> <h3>This is the second section </h3> </div>
  10. <div> <h3>This is the third section </h3> </div>
  11. <div> <h3>This is the fourth section </h3> </div>
  12. </div>

 

 

2.编写css样式

  1. 设定label的大小为宽400,高500,位置和文字都居中。
  2. 设定ul的大小为宽400,高50,
  3. 设定li的大小为宽100,高50,无头部样式,向左浮动,默认的背景色为灰色,文字为白色上下居中。
  4. 设定下面的内容宽400,高50,绝对定位(让四个div重叠),文字为白色,背景为灰黑色,默认隐藏。
  5. li标签中的showed类就是现在要展示的标签,突出展示,颜色为灰黑色,顶部有橘色的边框,文字调整高度居中,设置阴影突出立体感。
  6. div标签中的showed类就是对应展现的内容了,display改为block显示,并设置阴影突出立体感。
  7. 代码如下:

 
 
  1. *{
  2. margin: 0px;
  3. padding: 0px;
  4. }
  5. .label{
  6. width: 400px;
  7. height: 500px;
  8. margin: 120px auto;
  9. text-align: center;
  10. }
  11. .label> ul{
  12. width: 400px;
  13. height: 50px;
  14. }
  15. .label> ul> li{
  16. list-style: none;
  17. float: left;
  18. width: 100px;
  19. height: 50px;
  20. background-color: gray;
  21. line-height: 50px;
  22. color: white;
  23. }
  24. .label> div{
  25. width: 400px;
  26. height: 500px;
  27. position: absolute;
  28. color: white;
  29. line-height: 70px;
  30. background-color: #222222;
  31. display: none;
  32. }
  33. .label li .showed{
  34. background-color: #222222;
  35. border-top: 5px solid orange;
  36. line-height: 40px;
  37. box-shadow: 5px 5px 20px #333333;
  38. }
  39. .label div .showed{
  40. display: block;
  41. box-shadow: 5px 5px 20px #333333;
  42. }

 

 

3.编写js

  1. 首先引入jqurey
  2. 当鼠标悬停在li标签上时,如果不是showed类的话(不是当前展现的内容),执行以下步骤
  3. 将带有showed类的标签去掉showed类
  4. 将当前的li添加上showed类
  5. 将当前对象li标签在父标签中的位置index()对应的内容div也添上showed类

 
 
  1. <script type= "text/javascript" src= "jquery-1.6.js"> </script>
  2. <script>
  3. $( ".label li").mouseenter( function () {
  4. if(! $( this).hasClass( ".showed")){
  5. $( ".showed").removeClass( "showed");
  6. $( this).addClass( "showed");
  7. $( ".label>div").eq($( this).index()).addClass( "showed");
  8. }
  9. })
  10. < /script>

 

4.完成

这样简单的几个步骤就完成动态的页面效果,演示在文章的开头,完整的demo文件在百度网盘中。

标签卡Demo.html演示文件:百度网盘 https://pan.baidu.com/s/1bpVwQuV

 

 

 

 

 

 

  •                     <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#csdnc-thumbsup"></use>
                        </svg><span class="name">点赞</span>
                        <span class="count">1</span>
                        </a></li>
                        <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-Collection-G"></use>
                        </svg><span class="name">收藏</span></a></li>
                        <li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-fenxiang"></use>
                        </svg>分享</a></li>
                        <!--打赏开始-->
                                                <!--打赏结束-->
                                                <li class="tool-item tool-more">
                            <a>
                            <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                            </a>
                            <ul class="more-box">
                                <li class="item"><a class="article-report">文章举报</a></li>
                            </ul>
                        </li>
                                            </ul>
                </div>
                            </div>
            <div class="person-messagebox">
                <div class="left-message"><a href="https://blog.csdn.net/disILLL">
                    <img src="https://profile.csdnimg.cn/3/A/6/3_disilll" class="avatar_pic" username="disILLL">
                                            <img src="https://g.csdnimg.cn/static/user-reg-year/2x/2.png" class="user-years">
                                    </a></div>
                <div class="middle-message">
                                        <div class="title"><span class="tit"><a href="https://blog.csdn.net/disILLL" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">桂ILLL</a></span>
                                            </div>
                    <div class="text"><span>发布了4 篇原创文章</span> · <span>获赞 5</span> · <span>访问量 4583</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://im.csdn.net/im/main.html?userName=disILLL" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                        </a>
                                                            <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                    </div>
                            </div>
        </div>
    </article>
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值