【发布时间】:2019-09-18 01:40:21
【问题描述】:
我在 CodeIgnitor 上开发的博客中添加了一个响应式菜单。仅供参考,其他人制作了这个博客。 一切正常,但点击图标展开菜单时,移动设备中的菜单没有展开。
function myMenuFunction() {
var x = document.getElementById("nav");
if (x.className === "navMenuCustom") {
x.className += " responsive";
} else {
x.className = "navMenuCustom";
}
}
.navMenuCustom {
background-color: #333;
overflow: hidden;
font-weight: 900;
}
.navMenuCustom a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
text-decoration: none;
font-size: 17px;
padding: 8px 16px;
}
.navMenuCustom a:hover {
background-color: #ddd;
color: black;
}
.navMenuCustom a:active {
background-color: #4CAF50;
color: white;
}
.navMenuCustom .icon {
display: none;
}
@media screen and (max-width: 600px) {
.navMenuCustom a:not(:first-child) {
display: none;
}
.navMenuCustom a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.navMenuCustom.responsive {
position: relative;
}
.navMenuCustom.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.navMenuCustom.responsive a {
float: none;
display: block;
text-align: left;
}
}
<div id="nav" class="navMenuCustom">
<a href="/learn-guitar-fast">Learn Guitar Fast</a>
<a href="/teach-yourself-guitar">Teach Yourself Guitar</a>
<a href="/how-to-buy-a-guitar">How to Buy a Guitar</a>
<a href="/stringninja">String Ninja</a>
<a href="/easy-guitar-songs">Easy Guitar Songs</a>
<a href="/contact">Contact</a>
<a href="/blog">Blog</a>
<a href="javascript:void(0);" class="icon" onclick="myMenuFunction()">
<i class="fa fa-bars"></i>
</a>
</div>
我使用 w3schools 教程来添加响应式菜单。 Link to w3schools tutorial。 也可以查看直播网站here。
【问题讨论】:
-
刚刚为菜单添加了宽度和高度
a。.navMenuCustom a.icon { float: right; display: block; width: 20px; height: 20px; }这是一个小提琴链接:jsfiddle.net/6x9yczq2/2
标签: html css responsive