gpt4 book ai didi

javascript - 响应菜单下拉不显示

转载 作者:太空宇宙 更新时间:2023-11-04 13:24:21 25 4
gpt4 key购买 nike

我正在尝试使我的菜单具有响应性,但效果不佳。

菜单会更改大小等,但在按下“导航按钮”时不会显示菜单的下拉菜单。

你们能帮帮我吗? :)

CSS

/* #Base NAV 960 Grid
================================================== */

nav {
padding-top: 10px;
text-align:center;
margin: 0 auto;
}

nav ul {
display: inline;
list-style-type: none;
padding-left: 0px;
}

nav li {
display: inline;
padding-left: 55px;
padding-right: 55px;
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
text-transform: uppercase;
font-weight: 300;

}

nav li a:hover {
color:#808080;
-webkit-transition: all 0.3s ease-in-out;
}


nav li a {
color: #282828;
text-decoration: none;
font-size: medium;
}

.nav-button { display: none; }

.logoo { display: none; }
}

@media only screen and (min-width: 768px) and (max-width: 959px) {
nav li {
padding-left: 20px;
padding-right: 20px;
}
}


@media only screen and (min-width: 0px) and (max-width: 767px) {

/* Navigation Button
-------------------------------------------------------- */

nav ul img {
display: none;
}

.logoo {
display: inline;
width: 150px;
margin-top: 0px;
margin: 0 auto;
}

.nav-button {
display: block;
position: absolute;
top: 7px;
left: 7px;
width: 50px;
height: 35px;
background: url('../images/menu-icon-large.png'), -webkit-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background: url('../images/menu-icon-large.png'), -moz-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background: url('../images/menu-icon-large.png'), -ms-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background: url('../images/menu-icon-large.png'), -o-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background-position: center center;
background-repeat: no-repeat;
background-size: 21px, 100%;
cursor: pointer;
border: 0 none;
border-bottom: 1px solid rgba(255,255,255,.1);
box-shadow: 0 0 4px rgba(0,0,0,.7) inset;
border-radius: 5px;
z-index: 999;
text-indent: -9999px;
}
.nav-button:hover {
background-color: rgba(0,0,0,.1);
}
.nav-button.open {
background: url('../images/close-icon-large.png'), -webkit-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background: url('../images/close-icon-large.png'), -moz-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background: url('../images/close-icon-large.png'), -ms-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background: url('../images/close-icon-large.png'), -o-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background-position: center center;
background-repeat: no-repeat;
background-size: 21px, 100%;
}

/* Navigation Bar
-------------------------------------------------------- */

body { padding-top: 50px; }

nav {
width: 100%;
float: none;
background-color: #b0b0b0; /* change the menu color */
background-image: -webkit-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background-image: -moz-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background-image: -ms-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
background-image: -o-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,.2));
display: block;
height: 50px;
margin: 0;
padding: 0;
overflow: hidden;
box-shadow: 0 1px 2px rgba(0,0,0,.6);
position: absolute;
left: 0px;
z-index: 998;
clear: both;
}
nav li {
display: none;
width: 100%;
}
nav li a {
display: block;
width: 90%;
padding: 10px 5%;
font-size: 14px;
font-weight: bold;
text-shadow: -1px -1px 0 rgba(0,0,0,.15);
color: white;
text-decoration: none;
border-bottom: 1px solid rgba(0,0,0,.2);
border-top: 1px solid rgba(255,255,255,.1);
}
nav li a:hover {
background-color: rgba(0,0,0,.5);
border-top-color: transparent;
}
nav > li:first-child {
border-top: 1px solid rgba(0,0,0,.2);
}

/* Toggle the navigation bar open */

nav.open {
height: auto;
padding-top: 50px;
}
nav.open li {
display: block;
}

/* Submenus – optional .parent class indicates dropdowns */

nav > li:hover > a {
background: rgba(0,0,0,.5);
border-bottom-color: transparent;
}
nav li.parent > a:after {
content: "▼";
color: rgba(255,255,255,.5);
float: right;
}
nav li.parent > a:hover {
background: rgba(0,0,0,.75);
}
nav li ul {
display: none;
background: rgba(0,0,0,.5);
border-top: 0 none;
padding: 0;
}
nav li ul a {
border: 0 none;
font-size: 12px;
padding: 10px 5%;
font-weight: normal;
}
nav li:hover ul {
display: block;
border-top: 0 none;
}

}

JS

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<meta name="viewport" content="width=device-width">
<script>


$(document).ready(function(){
$(".nav-button").click(function () {
$(".nav-button,.primary-nav").toggleClass("open");
});


});
</script>

HTML

    <header>
<a href="index.php"><img class="logoo" src="images/logo.png"></a>
<nav>
<button class="nav-button">Toggle Navigation</button>
<ul>
<li> <a href="index.php"> home </a> </li>
<img src="images/dott.png" width="8px">
<li> <a href="about.php"> about </a> </li>
<a href="index.php"> <img src="images/logo.png" alt="Logo" width="180px"> </a>
<li> <a href="portfolio.php"> portfolio </a> </li>
<img src="images/dott.png" width="8px">
<li> <a href="#" target="_blank"> blog </a> </li>

</ul>

</nav>

</header>

最佳答案

您的元素上似乎缺少“primary-nav”类,您当前正在使用 jQuery 和样式对其进行选择。

将你的CSS改成这样:

.primary-nav.open { 
height: auto;
padding-top: 50px;

}
.primary-nav.open li {
display: block;
}

和你的 JS:

$(document).ready(function(){
$(".nav-button").click(function () {
$(".primary-nav").toggleClass("open");
});

最后,将类(class)添加到您的 <nav> :

<nav class="primary-nav">

关于javascript - 响应菜单下拉不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23838480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com