【问题标题】:Dropdown closing too early Html CSS下拉关闭太早 Html CSS
【发布时间】:2017-05-15 01:46:42
【问题描述】:

我最近和我的朋友在编写一个网站时遇到了我的导航栏下拉错误并且它似乎关闭得太早了。这是该站点的相关 HTML/CSS。如何修复下拉菜单?

body {
  background-image: url("http://equinoxhosting.net/cdn.wallpapersafari.com/14/86/kujVXw.jpg");
  background-size: cover;
  margin: 0;
  padding: 0;
}

/* ~~ Top Navigation Bar ~~ */

#navigation-container {
  width: 1200px;
  margin: 0 auto;
  height: 84px;
}

.navigation-bar {
    
  background-color: rgba(0, 0, 0, 0.25);
  width: 100%;    
}

.navigation-bar ul {
  padding: 0px;
  margin: 0px;
  text-align: center;
}

.navigation-bar li  {
  list-style-type: none;
  padding: 0px;
  height: 24px;
  margin-top: 4px;
  margin-bottom: 4px;
  display: inline;
}

.navigation-bar li a {
  position: relative;
  color: white;
  font-size: 16px;
  font-family: sans-serif;
  text-decoration: none;
  line-height: 70px;
  padding: 5px 35px;

}

#menu {
  float: right;
}
.navbrand {
    font-family: sans-serif;
    color: white;
    position: absolute;
    top: 15px;
    left: 90px;  
}
li a, .dropbtn {
    display: inline-block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn {
    background-color: gray;
}

li.dropdown {
    display: inline-block;
}

.dropdown-content { 
    display: none;
    position: absolute;
    background-color: rgba(0, 0, 0, 0.25);
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-content a:hover {background-color: gray}

.dropdown:hover .dropdown-content {
    display: block;
}
div.inner {
    position: relative;
 background-color: white;
padding: 250px;
    top: 150px;
}

h2 {
    position: relative;
    bottom: 255px;
    font-family: sans-serif;
}
p3 {
    font-family: sans-serif;
    position: relative;
    bottom: 260px;
}

h3 {
    position: relative;
    font-family: sans-serif;
    top: 60px;
    cursor: default;
}
p4 {
    position: relative;
    font-family: sans-serif;
    top: 35px;
}

.button {
    position: relative;
    background-color: #1DB2E3;
    border: 2px;
    border-radius: 25px;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
    top: 70px;
}
<div class="navbrand">
  <p><font size="5">Equinox Hosting</font></p>
</div>
<div id="menuwrapper">
<div class="navigation-bar">
  <div class="navbar-inner">
    <div id="navigation-container">
      <ul>
        <li><a href="index.html">Home</a></li>
        <li class="dropdown">
          <a href="javascript:void(0)" class="dropbtn">Hosting</a>
          <div class="dropdown-content">
            <a href="minecraft-hosting.html">Minecraft Hosting</a>
            <a href="dedicated-hosting.html">Dedicated Hosting</a>
            <a href="web-hosting.html">Website Hosting</a>
        <li class="dropdown">
        <a href="javascript:void(0)" class="dropbtn">Login</a>
        <div class="dropdown-content">
        <a href="#">Client Area</a>
        <a href="#">Xeon Panel</a>
        <a href="#">Cpanel</a>
        </div>
        </div>
        </li>
      </ul>
    </div>
  </div>
</div>
<div class="getstarted">
  <center>
    <font size="6">
      <font color="white">
        <h3>HOSTING FOR EVERYONE</h3>
      </font>
    </font>
    <font size="4">
      <font color="white">
        <p4>Want to get 10% off? Use code LAUNCH10</p4>
      </font>
    </font>
    <br>
    <button class="button">Get Started Now</button>
  </center>
</div>
<div class="inner">
  <center>
    <h2 class="title">About Us</h2>
    <b>
      <font size="4">
        <p3>We are Equinox Hosting, launched in 2017 with a passion for providing our customers with the highest quality services <br> and solutions at the lowest prices, affordable for everyone. We always try to answer support tickets & questions as<br> soon as possible, so if you do have any questions or queries regarding our services head to our contact page.</p3>
      </font>
    </b>
  </center>
</div>

【问题讨论】:

  • 抱歉,我在您的示例中看不到您的问题。

标签: html css navbar dropdown


【解决方案1】:

您可以通过在#navigation-container 上设置relative 位置和z-index 值来解决此问题:

#navigation-container {
  width: 1200px;
  margin: 0 auto;
  height: 84px;
  z-index: 1;
  position: relative;
}

这里是您的 jsfiddle 的更新:
https://jsfiddle.net/dekelb/wv9yvexu/

你的问题是你的标题(HOSTING FOR EVERYONE)有一个相对位置,它接管了菜单(或菜单停留在那个元素后面),所以当你 hover 那个标题 - menu 不是“悬停" 并再次被隐藏。

CSS 中的上述更改将解决此问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    相关资源
    最近更新 更多