【发布时间】:2018-04-20 12:04:55
【问题描述】:
我真的不想失去悬停能力,我需要一种不失去悬停能力的方法。
在纯 CSS(无 JavaScript)中,如何在不丢失悬停功能的情况下关闭下拉菜单?
这里有一个例子,他做了一个带有关闭外部点击功能的 JavaScript 下拉菜单。
https://koen.kivits.com/articles/pure-css-menu/
这是我的带有悬停和 onClick 的下拉菜单 CSS:
.acn-menu {
text-align: center;
background-color: rgba(0, 0, 0, 0.9);
}
.label_openclose {
display: none;
}
.menu-tabs {
height: 100%;
padding-left: 0;
padding-right: 0;
padding-top: 0;
padding-bottom: 0;
}
/* This CSS makes the Solutions dropdown menu push
down the other two items when in mobile view. */
@media (min-width: 320px) {
.menu-tabs {
position: absolute;
}
}
.menu-tabs .elem {
box-sizing: border-box;
padding: 0 20px;
float: left;
height: 100%;
line-height: 70px;
background-color: rgb(30, 30, 30);
color: white;
}
.menu-check {
display: none;
}
label {
margin-bottom: 0;
}
.label_openclose {
display: inline-block;
width: 60px;
min-height: 50px;
background-color: transparent;
cursor: pointer;
overflow:hidden;
display:block;
}
.menu-tabs .elem {
line-height: initial;
float: initial;
height: 0px;
cursor: pointer;
border-top: 0px solid #000;
overflow: hidden;
}
.menu-check:checked~.menu-tabs .elem {
height: 25px;
color: white;
border-top: 2px solid rgba(255, 255, 255, 0.2);
}
.label_openclose:hover~.menu-tabs .elem {
border-top: 2px solid rgba(255, 255, 255, 0.2);
height: 25px;
}
.label_openclose~.menu-tabs:hover .elem {
border-top: 2px solid rgba(255, 255, 255, 0.2);
height: 25px;
}
我是否可以在不使用 JS 的情况下获得点击关闭?这是一个小提琴:https://jsfiddle.net/Ld5L2tnf/
【问题讨论】:
-
我已从您的帖子中删除了免费工作的请求 - 请始终假设人们愿意提供帮助,但不希望成为免费劳动力的来源。
标签: html css twitter-bootstrap twitter-bootstrap-3 drop-down-menu