gpt4 book ai didi

javascript - 回滚菜单时 CSS 下拉菜单跳转

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

我遇到了一个问题,即我的 CSS 菜单在回滚时跳转到不同的位置。知道我该如何解决吗? JSfiddle 在这里:http://jsfiddle.net/KVrFM/2/

CSS

#header_dropdown {
float: right;
}
.click-nav {
width: 200px;
}
.click-nav ul {
position: relative;
}
.click-nav ul li {
position: relative;
list-style: none;
cursor: pointer;
}
.click-nav ul li ul {
position: absolute;
}
.click-nav ul .clicker {
position: relative;
background: #2284B5;
color: #FFF;
}
.click-nav ul .clicker:hover, .click-nav ul .active {
background: #196F9A;
}
.click-nav ul li a {
transition: background-color 0.2s ease-in-out;
-webkit-transition: background-color 0.2s ease-in-out;
-moz-transition: background-color 0.2s ease-in-out;
display: block;
background: #FFF;
color: #333;
text-decoration: none;
}
.click-nav ul li a:hover {
background: #F2F2F2;
}
/* Fallbacks */
.click-nav .no-js ul {
display: none;
}
.click-nav .no-js:hover ul {
display: block;
}
.active ul {
padding: 0;
}

JavaScript

$(function () {
$('.click-nav > ul').toggleClass('no-js js');
$('.click-nav .js ul').hide();
$('.click-nav .js').click(function (e) {
$('.click-nav .js ul').slideToggle(200);
$('.clicker').parent().toggleClass('active');
e.stopPropagation();
});
$(document).click(function () {
if ($('.click-nav .js ul').is(':visible')) {
$('.click-nav .js ul', this).slideUp();
$('.clicker').removeClass('active');
}
});
});

HTML

<div id="header_dropdown">
<div class="click-nav">
<ul class="no-js">
<li> <a href="#" class="clicker">Profile</a>

<ul>
<li><a href="#">Dashboard</a>

</li>
<li><a href="#">Settings</a>

</li>
<li><a href="#">Privacy</a>

</li>
<li><a href="#">Help</a>

</li>
<li><a href="#">Sign out</a>

</li>
</ul>
</li>
</ul>
</div>
</div>

最佳答案

简单地向 ul 添加填充 0

http://jsfiddle.net/KVrFM/3/

.click-nav ul li ul {
position: absolute;
padding:0;

}

关于javascript - 回滚菜单时 CSS 下拉菜单跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18042398/

25 4 0