CSS高级篇:响应式导航条

我很懒,懒到什么程度,算了,懒得说了......

直接上代码

body:

 

 1 <div class="container">
 2     <ul>
 3         <li>首页</li>
 4         <li>贴吧</li>
 5         <li>糯米</li>
 6         <li>翻译</li>
 7         <li>地图</li>
 8         <li>图片</li>
 9         <li>知道</li>
10     </ul>
11     <div class="menu"></div>
12 </div>    

css:

 1 <style type="text/css">
 2     * {
 3         margin: 0px;
 4         padding: 0px;
 5     }
 6             
 7     .container {
 8         background-color: #333;
 9         height: 48px;
10         position: relative;
11     }
12             
13     .container ul {
14         padding-left: 100px;
15     }
16             
17     .container ul li {
18         list-style: none;
19         float: left;
20         width: 100px;
21         color: rgba(255, 255, 255, 0.8);
22         text-align: center;
23         height: 48px;
24         line-height: 48px;
25         cursor: pointer;
26     }
27             
28     .container ul li:hover {
29         color: rgba(255, 255, 255, 1);
30     }
31             
32     .container .menu {
33         width: 40px;
34         height: 30px;
35         border: 2px solid white;
36         position: absolute;
37         line-height: 30px;
38         text-align: center;
39         border-radius: 6px;
40         color: white;
41         cursor: pointer;
42         right: 40px;
43         top: calc((48px - 34px) / 2);
44         display: none;
45         -webkit-user-select: none;
46     }
47             
48     @media all and (max-width: 767px) {
49             .container .menu {
50             display: block;
51         }
52     .container ul {
53             position: absolute;
54             top: 50px;
55             padding-left: 0px;
56             right: 10px;
57             display: none;
58         }
59         .container ul li {
60             float: none;
61             background-color: #333;
62             border-radius: 4px;
63             margin-bottom: 1px;
64         }
65         .container ul li:hover {
66             background-color: #333;
67             opacity: 0.9;
68         }
69     }
70 </style>

额,由于出了点小问题,so,加了点script代码

script:

 1 <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
 2     <script type="text/javascript">
 3         $(".menu").toggle(
 4             function() {
 5                 $(this).css("background-color", "rgba(255,255,255,0.5)");
 6                 $(".container ul").slideDown(200);
 7             },
 8             function() {
 9                 $(this).css("background-color", "transparent");
10                 $(".container ul").slideUp(200);
11             }
12         );
13         $(window).resize(function() {
14             if($(this).width() > 767) $(".container ul").show(500);    
15         });
16 </script>

 

PC端效果:

移动端效果:

OK,完活。 O(∩_∩)O

转载于:https://www.cnblogs.com/WHongy/p/7832824.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值