侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

支持IE8的纯css3开发的响应式设计动画菜单教程

前端  /  管理员 发布于 7年前   184

  这是一个响应式设计的菜单。单击列表图标,当你显示屏大小可以完全水平放下所有菜单项时,菜单水平显示(如图1)。当你的显示屏不能水平放置所有菜单项时,菜单垂直显示(如图2)。 而且显示的时候是以动画的型式显示。效果相当的好。

图1

图2

  下面是实现的代码。

  html代码:

XML/HTML Code复制内容到剪贴板
  1. <div class="container">  
  2.         <!--[if lte IE 8]>  
  3. <style>  
  4.   
  5.         .iconicmenu > label{   
  6.         border-width: 7px;   
  7.         background: #eee;   
  8.         }   
  9.            
  10.         .iconicmenu:hover ul{   
  11.             left: 8px; /* show menu onmouseover in IE8 and below */   
  12.         }   
  13.   
  14. </style>  
  15. <![endif]-->  
  16.         <div class="iconicmenu">  
  17.             <input type="checkbox" id="togglebox" />  
  18.             <ul>  
  19.                 <li><a targe="_blank" href="https:///Shili/css3%E8%8F%9C%E5%8D%95">Home</a></li>  
  20.                 <li><a targe="_blank" href="https:///Shili/css3%E8%8F%9C%E5%8D%95">DHTML</a></li>  
  21.                 <li><a targe="_blank" href="https:///Shili/css3%E8%8F%9C%E5%8D%95">CSS Library</a></li>  
  22.                 <li><a targe="_blank" href="https:///Shili/css3%E8%8F%9C%E5%8D%95">CSS Gallery</a></li>  
  23.                 <li><a targe="_blank" href="https:///Shili/css3%E8%8F%9C%E5%8D%95">JavaScript</a></li>  
  24.                 <li>  
  25.                     <label for="togglebox">  
  26.                     </label>  
  27.                 </li>  
  28.             </ul>  
  29.             <label class="toggler" for="togglebox">  
  30.                 Menu</label>  
  31.         </div>  
  32.     </div>  

  这里加入了兼容ie8的hack 。

  css代码:

CSS Code复制内容到剪贴板
  1. body   
  2.         {   
  3.             padding:0; margin:0;   
  4.             }   
  5.             .container   
  6.             {   
  7.                  width:600px;  margin:auto;   
  8.                 }   
  9.             .iconicmenu {   
  10.     position: relative;   
  11.     height: 45px;   
  12.     overflow: hidden;   
  13.     }   
  14.   
  15. .iconicmenu, .iconicmenu * {   
  16.     -moz-box-sizing: border-box;   
  17.     box-sizing: border-box;   
  18.     }   
  19.   
  20. .iconicmenu input[type="checkbox"] { /* checkbox used to toggle menu state */  
  21.     position: absolute;   
  22.     left: 0;   
  23.     top: 0;   
  24.     opacity: 0;   
  25.     }   
  26.   
  27. .iconicmenu > label { /* Main label icon to toggle menu state */  
  28.     z-index: 1000;   
  29.     display: block;   
  30.     position: absolute;   
  31.     width: 40px;   
  32.     height: 40px;   
  33.     float: left;   
  34.     top: 0;   
  35.     left: 0;   
  36.     background: white;   
  37.     text-indent: -1000000px;   
  38.     border: 6px solid black; /* border color */  
  39.     border-width: 6px 0;   
  40.     cursor: pointer;   
  41.     -moz-transition: all 0.3s ease-in;   
  42.     -webkit-transition: all 0.3s ease-in;   
  43.     transition: all 0.3s ease-in; /* transition for flipping label */  
  44.     }   
  45.   
  46. .iconicmenu > label::after { /* inner stripes inside label */  
  47.     content: "";   
  48.     display: block;   
  49.     position: absolute;   
  50.     width: 100%;   
  51.     height: 18%;   
  52.     top: 19%;   
  53.     left: 0;   
  54.     border: 6px solid black; /* border color */  
  55.     border-width: 6px 0;   
  56.     -moz-transition: all 0.3s ease-in;   
  57.     -webkit-transition: all 0.3s ease-in;   
  58.     transition: all 0.3s ease-in; /* transition for flipping label */  
  59.     }   
  60.   
  61. .iconicmenu ul { /* UL menu inside container */  
  62.     margin: 0;   
  63.     padding: 0;   
  64.     position: absolute;   
  65.     margin-left: 40px;   
  66.     background: #eee;   
  67.     left: -100%; /* hide menu intially */  
  68.     height: 40px; /* height of menu */  
  69.     font: bold 14px Verdana;   
  70.     text-align: center;   
  71.     list-style: none;   
  72.     opacity: 0;   
  73.     -moz-border-radius: 0 5px 5px 0;   
  74.     -webkit-border-radius: 0 5px 5px 0;   
  75.     border-radius: 0 5px 5px 0;   
  76.     -moz-perspective: 10000px;   
  77.     perspective: 10000px;   
  78.     -moz-transition: all 0.5s ease-in;   
  79.     -webkit-transition: all 0.5s ease-in;   
  80.     transition: all 0.5s ease-in; /* transition for animating UL in and out */  
  81.     }   
  82.   
  83. .iconicmenu li {   
  84.     display: inline;   
  85.     margin: 0;   
  86.     padding: 0;   
  87.     }   
  88.   
  89. .iconicmenu ul label { /* label button inside UL to close menu */  
  90.     cursor: pointer;   
  91.     position: relative;   
  92.     height: 100%;   
  93.     text-align: center;   
  94.     }   
  95.   
  96. .iconicmenu ul label::after { /* label button x */  
  97.     content: "x";   
  98.     display: inline-block;   
  99.     line-height: 14px;   
  100.     color: white;   
  101.     -moz-border-radius: 50px;   
  102.     -webkit-border-radius: 50px;   
  103.     border-radius: 50px;   
  104.     width: 20px;   
  105.     height: 20px;   
  106.     background: black;   
  107.     font-size: 18px;   
  108.     margin: 5px;   
  109.     margin-top: 10px;   
  110.     -moz-transition: all 0.3s ease-in;   
  111.     -webkit-transition: all 0.3s ease-in;   
  112.     transition: all 0.3s ease-in;   
  113.     }   
  114.   
  115. .iconicmenu input[type="checkbox"]:checked ~ label, .iconicmenu ul label:hover::after {   
  116.     -moz-transform: rotatey(180deg);   
  117.     -ms-transform: rotatey(180deg);   
  118.     -webkit-transform: rotatey(180deg);   
  119.     transform: rotatey(180deg); /* flip labels vertically onMouseover */  
  120.     }   
  121.   
  122. .iconicmenu > label:hover, .iconicmenu > label:hover::after, .iconicmenu input[type="checkbox"]:checked ~ label, .iconicmenu input[type="checkbox"]:checked ~ label::after {   
  123.     border-color: darkred; /* highlight color of main menu label onMouseover */  
  124.     }   
  125.   
  126. .iconicmenu input[type="checkbox"]:checked ~ ul {   
  127.     left: 8px; /* Animate menu into view */  
  128.     opacity: 1;   
  129.     -moz-box-shadow: 1px 1px 5px gray;   
  130.     -webkit-box-shadow: 1px 1px 5px gray;   
  131.     box-shadow: 1px 1px 5px gray;   
  132.     }   
  133.   
  134. .iconicmenu li a {   
  135.     display: block;   
  136.     float: left;   
  137.     text-align: center;   
  138.     text-decoration: none;   
  139.     color: black;   
  140.     margin: 0;   
  141.     padding: 10px;   
  142.     padding-right: 15px;   
  143.     height: 100%;   
  144.     }   
  145.   
  146. .iconicmenu li a:hover {   
  147. .social-share p{font-size:8px;}

  • 上一条:
    纯CSS3实现自定义Tooltip边框涂鸦风格的教程
    下一条:
    一款利用纯css3实现的360度翻转按钮的实例教程
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 使用 Alpine.js 排序插件对元素进行排序(0个评论)
    • 在js中使用jszip + file-saver实现批量下载OSS文件功能示例(0个评论)
    • 在vue中实现父页面按钮显示子组件中的el-dialog效果(0个评论)
    • 使用mock-server实现模拟接口对接流程步骤(0个评论)
    • vue项目打包程序实现把项目打包成一个exe可执行程序(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-10
    • 2017-11
    • 2018-03
    • 2018-04
    • 2018-05
    • 2018-06
    • 2018-09
    • 2018-11
    • 2018-12
    • 2019-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-04
    • 2021-05
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客