以下是实现HTML5响应式导航的一个示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| <!DOCTYPE html> <head> <title>响应式导航</title> <meta charset="utf-8"> <style type="text/css"> body { margin: 0; }
.topnav { overflow: hidden; background-color: }
.topnav a { float: left; display: block; color: text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; }
.topnav a:hover { background-color: color: black; }
.topnav .icon { display: none; }
@media screen and (max-width: 600px) { .topnav a:not(:first-child) { display: none; }
.topnav a.icon { float: right; display: block; }
.container { display: inline-block; cursor: pointer; }
.bar1, .bar2, .bar3 { width: 35px; height: 5px; background-color: margin: 6px 0; transition: 0.4s; }
.change .bar1 { -webkit-transform: rotate(-45deg) translate(-9px, 6px); transform: rotate(-45deg) translate(-9px, 6px); }
.change .bar2 { opacity: 0; }
.change .bar3 { -webkit-transform: rotate(45deg) translate(-8px, -8px); transform: rotate(45deg) translate(-8px, -8px); } }
@media screen and (max-width: 600px) { .topnav.responsive { position: relative; }
.topnav.responsive .icon { position: absolute; right: 0; top: 0; }
.topnav.responsive a { float: none; display: block; text-align: left; } } </style> <script type="text/javascript"> function myFunction(iconid) { iconid.classList.toggle("change"); var x = document.getElementById("myTopnav"); if (x.className === "topnav") { x.className += " responsive"; } else { x.className = "topnav"; } } </script> </head> <body> <div class="topnav" id="myTopnav"> <a href="#home">主页</a> <a href="#news">新闻中心</a> <a href="#contact">联系我们</a> <a href="#about">关于</a> <a href="javascript:void(0);" style="font-size:15px;" class="icon"> <!--& <div class="container" onclick="myFunction(this)"> <div class="bar1"></div> <div class="bar2"></div> <div class="bar3"></div> </div> </a> </div> <div style="padding-left:16px"> <h2>标题</h2> <p>内容</p> </div> </body>
|