CSS 重叠菜单导航链接

CSS Overlaps Menu Navigation Links

在最大宽度为 768px 的媒体查询中,关于菜单下的子菜单与课程菜单重叠,我希望它在点击时下推以显示子菜单。我尝试了很多选择,但没有用。任何帮助将不胜感激。

var navLinks = document.getElementById("navLinks");

function displayMenu() {
navLinks.style.right = "0";
}

function hideMenu() {
navLinks.style.right = "-200px";
}
nav{
    display: flex;
    align-items: center;
    padding: 2% 6%;
    justify-content: space-between;
}

.nav-links{
    flex: 1;
    text-align: right;
}

.nav-links ul li{
    display: inline-block;
    padding: 8px 12px;
    position: relative;
    list-style: none;
}

.nav-links ul li a{
    color: #000;
    text-decoration: none;
    font-size: 15px;
}

.nav-links ul li::after{
    content: "";
    width: 0%;
    height: 2px;
    background:  #ff5733;
    display: block;
    margin: auto;
}

.nav-links ul li:hover::after{
    width: 100%;
    transition: 0.5s;
}

.nav-links ul li:nth-child(2):hover::after{
    background: none;
    width: 0;
}

nav .fa{
    display: none;
}

nav .fa-chevron-down{
    display: inline;
    margin-right: 6px;
}

.sub-menu-1{
    display: none;
}

.nav-links ul li:hover .sub-menu-1{
    display: block;
    position: absolute;
    background-color: #ff5733;
    margin-top: 15px;
    margin-left: -15PX;
}

.nav-links ul li:hover .sub-menu-1 ul{
    display: block;
    margin: 10px;
}

.nav-links ul li:hover .sub-menu-1 ul li{
    width: 150px;
    padding: 10px;
    border-bottom: 1px dotted #fff;
    background: transparent;
    border-radius: 0;
    text-align: left;
    text-transform: uppercase;
    font-weight: 500;
}

.nav-links ul li:hover .sub-menu-1 ul li:last-child{
    border-bottom: none;
}

.nav-links ul li:hover .sub-menu-1 ul li a:hover{
    color: bisque;
}
<html>
<body>
 <section>
<nav>
        <!-- Navigation Links -->
        <div class="nav-links" id="navLinks">
          <i class="fa fa-times" onclick="hideMenu()"></i>

          <ul>
            <li><a href="index.html">HOME</a></li>
            <li><a href="#"><i class="fa fa-chevron-down"></i>ABOUT</a>
              <div class="sub-menu-1">
                <ul>
                  <li><a href="message.html">Principal Message</a></li>
                  <li><a href="history.html">School History</a></li>
                  <li><a href="mission.html">Mission & Vision</a></li>
                </ul>
              </div>

            </li>
            <li><a href="course.html">COURSE</a></li>
            <li><a href="news.html">NEWS</a></li>
            <li><a href="gallery.html">GALLERY</a></li>
            <li><a href="contact.html">CONTACT</a></li>
          </ul>
        </div>
        <i class="fa fa-bars" onclick="displayMenu()"></i>
      </nav>
  </section>
</body>
</html>

Fiddle demo

我添加了这两条规则,它似乎表现得更好。

这会为所有内容设置默认值(不是必需的),以便我们知道要更改的内容

.nav-links ul, .nav-links ul li{
  position:relative;
  z-index:0;
}

这会将您悬停在上面的内容设置为最上面。我喜欢一次至少将 z-index 调整 10,因为它为您提供了以后需要时在它们之间插入的空间,而无需调整其他所有内容。

.nav-links ul li:hover{
  z-index:10;
}