二级菜单仅在野生动物园中不打开

时间:2018-06-21 17:57:20

标签: html html5 css3 safari

仅在Safari中,二级菜单出现问题。顶层和子菜单在chrome,firefox等鼠标悬停时可以正常工作,但是在Safari中打开时,只有第一个菜单在悬停时打开。我已经尝试过这里和其他论坛上提供的其他解决方案,但是仍然是一样的。

.nav {
    margin: 2% 10% 0 35%;
    /*margin-bottom: 4px;
    margin-top: 2%;
    margin-left: 35%;
    margin-right: 10%;*/
    width: 60%;
    height: auto;
    z-index: 1;
    position: absolute;
}

.nav-container {
    display: inline-block;
    padding: 0;
    font-weight: 300;
    font-family:"Open Sans";
    font-size: 15px;
}

.nav-container a:hover {
    color: #FFFFFF;
}

.nav-pos {
    display: inline-block;
    padding-bottom: 15px;
}

.nav-pos-sp {
    /*padding-left: 30px;*/
    padding-left: 0px !important;
    margin-left: 30px;
}

.navbar-nav {
    margin-top: 1%;
    display: none;
    height: auto;
    color: #C7C7C7;
    width: 200px;
    overflow: hidden;
    position: fixed;
}

.navbar-nav-menu a {
    font-size: 14px;
    display: block;
    text-align: left;
    padding: 15px 0px 15px 12px;
    border-bottom: thin solid #fff;
    background-color: #343434;
}

/* child menu dropdown */
.navbar-nav-child {
    display: none;
    height: auto;
    color: #C7C7C7;
    width: 200px;
    overflow: hidden;
    position: fixed;
    margin-left: -200px;
    margin-top: -50px;
}

.navbar-nav-menu-item-101a:hover .navbar-nav-child {
        margin-left: 200px !important;
        display: block !important;
}

.navbar-nav-menu-child-text a {
        font-size: 14px;
        display: block;
        text-align: left;
        padding: 15px 0px 15px 12px;
        border-bottom: thin solid #fff;
        background-color: #2B2B2B;
}

.services:hover .navbar-nav-menu {
        display: block;
}
<html>
<head>
    <link rel="stylesheet" href="../style/all.css.cf.css" type="text/css"/>
    <link rel="stylesheet" type="text/css"
          href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
</head>
<body>

<div class="nav">
    <div class="nav-container">
        <div class="nav-pos nav-pos-sp services">
            <a href="#0" target="_blank">First Menu <span class="fa fa-angle-down"></span></a>
            <div class="navbar-nav navbar-nav-menu navbar-nav-services">
                <ul>
                    <li class="navbar-nav-menu-item-101a"><a href="#0">Second Level Menu <span class="fa fa-angle-right"
                                                                                                                                                          style="float: right;margin-right: 10px;"></span></a>
                        <div class="navbar-nav-child navbar-nav-menu-child-text">

                            <a href="#0" target="_blank">1</a>
                            <a href="#0" target="_blank">2</a>
                            <a href="#0" target="_blank">3</a>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
</body>
</html>

我已经为菜单添加了HTML和CSS代码。我还使用Windows操作系统在chrome上对其进行了检查,并且可以使用,但唯一的问题是野生动物园浏览器。

1 个答案:

答案 0 :(得分:1)

我有一些建议可能会有所帮助。

首先,我不建议使用position: fixed;来定位子菜单,因为fixed是相对于浏览器窗口的位置。您可能希望子菜单根据父窗口而不是窗口来定位。

第二,您在overflow: hidden;上有.navbar-nav,这意味着不属于其边界的任何内容-包括子菜单。

这是一个JSFiddle,其中包含您的代码片段的工作示例以及我的建议,并在Safari中进行了测试和工作:

.nav {
  margin: 2% 10% 0 35%;
  width: 60%;
  height: auto;
  z-index: 1;
  position: absolute;
}

.nav-container {
  display: inline-block;
  padding: 0;
  font-weight: 300;
  font-family: "Open Sans";
  font-size: 15px;
}

.nav-container a:hover {
  color: #FFFFFF;
}

.nav-pos {
  display: inline-block;
  padding-bottom: 15px;
}

.nav-pos-sp {}

.navbar-nav {
  margin-top: 1%;
  display: none;
  height: auto;
  color: #C7C7C7;
  width: 200px;
  position: relative;
}

.navbar-nav-menu a {
  font-size: 14px;
  display: block;
  text-align: left;
  padding: 15px 0px 15px 12px;
  border-bottom: thin solid #fff;
  background-color: #343434;
}

/* child menu dropdown */

.navbar-nav-child {
  display: none;
  height: auto;
  color: #C7C7C7;
  width: 200px;
  position: absolute;
  top: 0;
  left: 100%;
}

.navbar-nav-menu-item-101a:hover .navbar-nav-child {
  display: block !important;
}

.navbar-nav-menu-child-text a {
  font-size: 14px;
  display: block;
  text-align: left;
  padding: 15px 0px 15px 12px;
  border-bottom: thin solid #fff;
  background-color: #2B2B2B;
}

.services:hover .navbar-nav-menu {
  display: block;
}
<html>

  <head>
    <link rel="stylesheet" href="../style/all.css.cf.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
  </head>

  <body>

    <div class="nav">
      <div class="nav-container">
        <div class="nav-pos nav-pos-sp services">
          <a href="#0" target="_blank">First Menu <span class="fa fa-angle-down"></span></a>
          <div class="navbar-nav navbar-nav-menu navbar-nav-services">
            <ul>
              <li class="navbar-nav-menu-item-101a"><a href="#0">Second Level Menu <span class="fa fa-angle-right"
                                                                                                                                                          style="float: right;margin-right: 10px;"></span></a>
                <div class="navbar-nav-child navbar-nav-menu-child-text">

                  <a href="#0" target="_blank">1</a>
                  <a href="#0" target="_blank">2</a>
                  <a href="#0" target="_blank">3</a>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </body>

</html>

instantiated