- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我做了一个下拉菜单,但它不能正常工作。请参阅 fiddle 或代码:https://jsfiddle.net/9u6fc7wp/
$(document).ready(function() {
$(function() {
$(".links>li>a:not(.sub-menu a)").mouseenter(function() {
$(".sub-menu-bg").addClass("menu-bg-up");
setTimeout(function() {
$(".sub-menu").fadeIn();
}, 700);
});
$(".sub-menu-bg").mouseleave(function() {
$(".sub-menu").fadeOut();
setTimeout(function() {
$(".sub-menu-bg").removeClass("menu-bg-up");
}, 500);
});
}());
});
#wrapper {
height: 300px;
}
footer {
background: white;
color: #8a8a8a;
font-family: TWcenMTregular;
font-size: 1em;
text-transform: uppercase;
padding: 1vh 0;
position: relative;
z-index: 9100;
width: 100%;
}
footer .links {
text-align: center;
list-style: none;
}
footer .links>li {
float: left;
width: 24%;
position: relative;
}
footer .links li::after {
content: ' | ';
float: right;
}
footer .links li:last-child::after {
content: '';
}
footer .links li a {
color: #8a8a8a;
}
footer .links li:hover > a {
color: #9ebe2d;
}
footer .links li:hover .sub-menu li:first-child a {
color: #9ebe2d;
}
footer .sub-menu {
position: absolute;
bottom: 100%;
left: initial;
padding: 0px 0;
margin: 0!important;
font-family: TWcenMTregular;
font-size: 1em;
width: 100%;
height: 150px;
display: none;
}
footer .sub-menu li {
text-align: center;
}
footer .sub-menu li:first-child {
font-family: prismRegular;
padding: 0 0 10px 0;
}
footer .sub-menu li::after {
content: '';
margin: 0;
}
footer .sub-menu li a {
color: #8a8a8a;
}
footer .sub-menu li a:hover {
color: #9ebe2d;
}
footer .sub-menu-bg {
background: rgba(255, 255, 255, 0.8);
position: absolute;
bottom: 100%;
left: initial;
z-index: -5;
width: 100%;
display: block;
transition: 0.7s;
-webkit-transition: 0.7s;
-moz-transition: 0.7s;
-o-transition: 0.7s;
-ms-transition: 0.7s;
height: 0;
}
.menu-bg-up {
height: 165px !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<footer>
<ul class="links">
<li><a href="#">link1</a>
<ul class="sub-menu">
<li><a href="#">link1</a>
</li>
<li><a href="#">link2</a>
</li>
<li><a href="#">link3</a>
</li>
<li><a href="#">link4</a>
</li>
</ul>
</li>
<li><a href="#">link2</a>
<ul class="sub-menu">
<li><a href="#">link1</a>
</li>
<li><a href="#">link2</a>
</li>
<li><a href="#">link3</a>
</li>
<li><a href="#">link4</a>
</li>
</ul>
</li>
<li><a href="#">link3</a>
</li>
<li><a href="#">link4</a>
</li>
</ul>
<div class="sub-menu-bg"></div>
</footer>
如果你慢慢移动鼠标,它工作正常。我使用了使子菜单链接稍后出现的超时功能。如果将光标移动到其中一个链接并立即移动到链接将出现的空白位置。当光标与链接接触时,下拉菜单会消失。它必须只有在光标离开页脚时才会消失。在我看来,选择器似乎无法正常工作,但应该可以解决问题。我只想在 .links>li
如果只用 CSS 就可以做到这一点,请告诉我怎么做。我已经尽力了。我希望我清楚地解释了问题并随时提问。
提前致谢。
最佳答案
您可以在 CSS 中完成这一切。我在下面举了一个例子;
https://jsfiddle.net/9u6fc7wp/1/
.links {
position: relative;
width: 24%;
}
.links > a::after {
content: "|";
float: right;
}
.sub-menu {
visibility: hidden;
/* hides sub-menu */
opacity: 0;
position: absolute;
top: -172px;
left: 0;
width: 100%;
transform: translateY(2em);
z-index: -1;
transition: all 0.3s ease-in-out 0s, visibility 0s linear 0.3s, z-index 0s linear 0.01s;
}
.links:hover .sub-menu {
visibility: visible;
/* shows sub-menu */
opacity: 1;
z-index: 1;
transform: translateY(0%);
transition-delay: 0s, 0s, 0.3s;
/* this removes the transition delay so the menu will be visible while the other styles transition */
}
/* presentational */
body {
padding: 2%;
font: 18px/1.4 sans-serif;
}
footer {
position: relative;
top: 200px;
}
footer a {
color: #8a8a8a;
display: block;
padding: 0.5em 0px;
text-decoration: none;
}
footer a:hover {
color: #9ebe2d;
}
footer ul,
footer ul li {
list-style-type: none;
padding: 0;
margin: 0;
}
footer > ul {
background: white;
text-align: center;
}
footer > ul > li {
display: inline-block;
}
footer > ul > li:first-child {
border-left: none;
}
.sub-menu {
background: white;
}
<div id="wrapper"></div>
<footer>
<ul>
<li class="links"><a href="#">link1</a>
<ul class="sub-menu">
<li><a href="#">link1</a>
</li>
<li><a href="#">link2</a>
</li>
<li><a href="#">link3</a>
</li>
<li><a href="#">link4</a>
</li>
</ul>
</li>
<li class="links"><a href="#">link2</a>
<ul class="sub-menu">
<li><a href="#">link1</a>
</li>
<li><a href="#">link2</a>
</li>
<li><a href="#">link3</a>
</li>
<li><a href="#">link4</a>
</li>
</ul>
</li>
<li class="links"><a href="#">link3</a>
</li>
<li class="links"><a href="#">link4</a>
</li>
</ul>
<div class="sub-menu-bg"></div>
</footer>
关于javascript - jQuery 选择器无法与下拉菜单一起正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39838142/
|
我是一名优秀的程序员,十分优秀!