我正在修复当前的顶部导航栏,问题在于导航栏有时会有很多菜单可供选择,这取决于已登录用户拥有的权限,有些用户只能看到管理员可能会看到所有内容(大约16个菜单选项)的3或4个选项。
如果浏览器窗口最大化,则可以完美地看到菜单,如果浏览器窗口开始变小,菜单将根据窗口大小进行堆叠。有些菜单有子菜单,这些子菜单有时甚至有更多的子菜单,所以如果有2,3或4级菜单,菜单会退出视口,用户看不到选项是什么。
这是我当前顶部导航栏菜单的jsfiddle: https://jsfiddle.net/38qyt0gt/
这是一个jsfiddle,它使用了我从Codepen获取的代码片段并替换了一些部分以匹配我所拥有的实际菜单的设计,唯一的问题是此菜单也存在与当您将鼠标悬停在第一级时,某些菜单的子元素出现问题,子菜单会显示,但您无法选择它们或将它们悬停。
这是一个小video,展示了新导航栏的问题。
我已经尝试通过应用下一个选择器来修复它,但它也不起作用:
#TopMenu_dropnav > ul > li:hover > ul{
display: block;
}
希望有人可以提供帮助
修改
这是新菜单栏的CSS
* {
margin: 0;
padding: 0;
text-decoration: none;
}
.logo {
position: relative;
z-index: 123;
padding: 10px;
font: 18px verdana;
color: #FFFFFF;
float: left;
width: 15%;
display: none;
}
.logo a {
color: #FFFFFF;
}
nav {
position: relative;
width: 100%;
margin: 0 auto;
}
#TopMenu_dropnav,
#TopMenu_dropnav ul,
#TopMenu_dropnav ul li,
#TopMenu_dropnav ul li a,
#TopMenu_dropnav #head-mobile {
border: 0;
list-style: none;
line-height: 1;
display: block;
position: relative;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#TopMenu_dropnav:after,
#TopMenu_dropnav > ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#TopMenu_dropnav #head-mobile {
display: none;
}
#TopMenu_dropnav {
font-family: sans-serif;
background: #1976D2;
}
#TopMenu_dropnav > ul > li {
float: left;
}
#TopMenu_dropnav > ul > li > a {
padding: 17px;
font-size: 12px;
letter-spacing: 1px;
text-decoration: none;
color: #ddd;
font-weight: 700;
}
#TopMenu_dropnav > ul > li:hover > a,
#TopMenu_dropnav ul li.active a {
color: #fff;
}
#TopMenu_dropnav > ul > li:hover,
#TopMenu_dropnav ul li.active:hover,
#TopMenu_dropnav ul li.active,
#TopMenu_dropnav ul li.has-sub.active:hover{
background: #2196F3!important;
-webkit-transition: background .3s ease;
-ms-transition: background .3s ease;
transition: background .3s ease;
}
#TopMenu_dropnav > ul > li.has-sub > a {
padding-right: 30px;
}
#TopMenu_dropnav > ul > li.has-sub > a:after {
position: absolute;
top: 22px;
right: 11px;
width: 8px;
height: 2px;
display: block;
background: #ddd;
content: '';
}
#TopMenu_dropnav > ul > li.has-sub > a:before {
position: absolute;
top: 19px;
right: 14px;
display: block;
width: 2px;
height: 8px;
background: #ddd;
content: '';
-webkit-transition: all .25s ease;
-ms-transition: all .25s ease;
transition: all .25s ease;
}
#TopMenu_dropnav > ul > li.has-sub:hover > a:before {
top: 23px;
height: 0;
}
#TopMenu_dropnav ul ul {
position: absolute;
left: -9999px;
}
#TopMenu_dropnav ul ul li {
height: 0;
-webkit-transition: all .25s ease;
-ms-transition: all .25s ease;
background: #333;
transition: all .25s ease;
}
#TopMenu_dropnav li:hover > ul {
left: auto;
}
#TopMenu_dropnav li:hover > ul > li {
height: 35px;
}
#TopMenu_dropnav ul ul ul {
margin-left: 100%;
top: 0;
}
#TopMenu_dropnav ul ul li a {
border-bottom: 1px solid rgba(150, 150, 150, 0.15);
padding: 11px 15px;
width: 170px;
font-size: 12px;
text-decoration: none;
color: #ddd;
font-weight: 400;
}
#TopMenu_dropnav ul ul li:last-child > a,
#TopMenu_dropnav ul ul li.last-item > a {
border-bottom: 0;
}
#TopMenu_dropnav ul ul li:hover > a,
#TopMenu_dropnav ul ul li a:hover {
color: #fff;
background-color: #2196F3;
}
#TopMenu_dropnav ul ul li.has-sub > a:after {
position: absolute;
top: 16px;
right: 11px;
width: 8px;
height: 2px;
display: block;
background: #ddd;
content: ''
}
#TopMenu_dropnav ul ul li.has-sub > a:before {
position: absolute;
top: 13px;
right: 14px;
display: block;
width: 2px;
height: 8px;
background: #ddd;
content: '';
-webkit-transition: all .25s ease;
-ms-transition: all .25s ease;
transition: all .25s ease;
}
#TopMenu_dropnav ul ul > li.has-sub:hover > a:before {
top: 17px;
height: 0;
}
#TopMenu_dropnav ul ul li.has-sub:hover,
#TopMenu_dropnav ul li.has-sub ul li.has-sub ul li:hover {
background: #363636;
}
#TopMenu_dropnav ul ul ul li.active a {
border-left: 1px solid #333
}
#TopMenu_dropnav > ul > li.has-sub > ul > li.active > a,
#TopMenu_dropnav > ul ul > li.has-sub > ul > li.active> a {
border-top: 1px solid #333;
}
@media screen and (max-width:1000px) {
nav {
width: 100%;
}
.logo {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 46px;
text-align: center;
padding: 10px 0 0 0;
float: none;
display: inline;
}
#TopMenu_dropnav ul {
width: 100%;
}
#TopMenu_dropnav ul li {
width: 100%;
border-top: 1px solid #444;
}
#TopMenu_dropnav ul li:hover {
background: #363636;
}
#TopMenu_dropnav ul ul li,
#TopMenu_dropnav li:hover > ul > li {
height: auto;
}
#TopMenu_dropnav ul li a,
#TopMenu_dropnav ul ul li a {
width: 100%;
border-bottom: 0;
}
#TopMenu_dropnav > ul > li {
float: none;
}
#TopMenu_dropnav ul ul li a {
padding-left: 25px;
}
#TopMenu_dropnav ul ul li {
background: #333!important;
}
#TopMenu_dropnav ul ul li:hover {
background: #363636!important;
}
#TopMenu_dropnav ul ul ul li a {
padding-left: 35px;
}
#TopMenu_dropnav ul ul li a {
color: #ddd;
background: none;
}
#TopMenu_dropnav ul ul li:hover > a,
#TopMenu_dropnav ul ul li.active > a {
color: #fff;
}
#TopMenu_dropnav ul ul,
#TopMenu_dropnav ul ul ul {
position: relative;
left: 0;
width: 100%;
margin: 0;
text-align: left;
}
#TopMenu_dropnav > ul > li.has-sub > a:after,
#TopMenu_dropnav > ul > li.has-sub > a:before,
#TopMenu_dropnav ul ul > li.has-sub > a:after,
#TopMenu_dropnav ul ul > li.has-sub > a:before {
display: none;
}
#TopMenu_dropnav #head-mobile {
display: block;
padding: 23px;
color: #ddd;
font-size: 12px;
font-weight: 700;
}
.button {
width: 55px;
height: 46px;
position: absolute;
right: 0;
top: 0;
cursor: pointer;
z-index: 12399994;
}
.button:after {
position: absolute;
top: 22px;
right: 20px;
display: block;
height: 4px;
width: 20px;
border-top: 2px solid #dddddd;
border-bottom: 2px solid #dddddd;
content: '';
}
.button:before {
-webkit-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
position: absolute;
top: 16px;
right: 20px;
display: block;
height: 2px;
width: 20px;
background: #ddd;
content: '';
}
.button.menu-opened:after {
-webkit-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
top: 23px;
border: 0;
height: 2px;
width: 19px;
background: #fff;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
.button.menu-opened:before {
top: 23px;
background: #fff;
width: 19px;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
#TopMenu_dropnav .submenu-button {
position: absolute;
z-index: 99;
right: 0;
top: 0;
display: block;
border-left: 1px solid #444;
height: 46px;
width: 46px;
cursor: pointer;
}
#TopMenu_dropnav .submenu-button.submenu-opened {
background: #262626;
}
#TopMenu_dropnav ul ul .submenu-button {
height: 34px;
width: 34px;
}
#TopMenu_dropnav .submenu-button:after {
position: absolute;
top: 22px;
right: 19px;
width: 8px;
height: 2px;
display: block;
background: #ddd;
content: '';
}
#TopMenu_dropnav ul ul .submenu-button:after {
top: 15px;
right: 13px;
}
#TopMenu_dropnav .submenu-button.submenu-opened:after {
background: #fff;
}
#TopMenu_dropnav .submenu-button:before {
position: absolute;
top: 19px;
right: 22px;
display: block;
width: 2px;
height: 8px;
background: #ddd;
content: '';
}
#TopMenu_dropnav ul ul .submenu-button:before {
top: 12px;
right: 16px;
}
#TopMenu_dropnav .submenu-button.submenu-opened:before {
display: none;
}
#TopMenu_dropnav ul ul ul li.active a {
border-left: none;
}
#TopMenu_dropnav > ul > li.has-sub > ul > li.active > a,
#TopMenu_dropnav > ul ul > li.has-sub > ul > li.active > a {
border-top: none;
}
}
答案 0 :(得分:0)
将onclick=""
添加到您希望iOS识别为悬停元素的任何内容。试试这个:
<div onclick="">Click Me!</div>
或者可以使用CSS媒体查询根据视口改变大小,
@media only screen and (max-width: 768px) {
.your_class_here {
/* css style goes here; */
}
}