移动主菜单后悬停菜单问题

时间:2017-06-20 06:14:50

标签: html css

#header {
  height: 108px;
  width: 1140px;
  background-color: #faa220;
  position: relative;
}

#Logo2 {
  height: 108px;
  float: left;

}

#header links {
  height: 50px;
  float: left;
  list-style: none;
  padding-top: 10px;
}

#container {
  overflow: hidden;
  background-color: #faa220;
  font-family: Arial, Helvetica, sans-serif;
  position: absolute;
  bottom: 0;
  right: 215px;
}

.container a {
  float: left;
  font-size: 18px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  position: absolute;
}

.dropdown {
  float: left;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 18px;
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  cursor: pointer;
  }

.container a:hover, .dropdown:hover .dropbtn {
  background-color: #faa220;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #faa220;
  min-width: 100px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
  position: absolute;
}

.dropdown-content a {
  float: none;
  color: white;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
  position: absolute;
  bottom: 0;
}

.dropdown-content a:hover {
  background-color: #faa220;
  position: absolute;
  bottom: 0;
}

.dropdown:hover .dropdown-content {
  position: absolute;
  display: block;
  bottom: 0;
}
    <div id="header">
    <img src="../JPEG/i2i logo 2.jpg" align="left" id="Logo2" />
    <div id="container">
      <div class="dropdown">
            <a href="index.html"><button class="dropbtn">Home</button></a>
        </div><!--dropdown close div-->
        <div class="dropdown">
            <a href="about.html"><button class="dropbtn">About Us</button></a>
            <div class="dropdown-content">
                <a href="bio.html">Bio</a>
                <a href="news.html">News</a>
                <a href="partners.html">Partners</a>
            </div><!--dropdown-content close div-->
        </div><!--dropdown close div-->
        <div class="dropdown">  
            <a href="awards.html"><button class="dropbtn">Awards/Certifications</button></a>
        </div>
        <div class="dropdown">
            <a href="services.html"><button class="dropbtn">Services</button></a>
            <div class="dropdown-content">
                <a href="solar.html">Solar</a>
                <a href="water.html">Water</a>
                <a href="housing.html">Housing</a>
                <a href="training.html">Training</a>
                <a href="broadband.html">Broadband</a>
            </div><!--dropdown-content close div-->
        </div><!--dropdown close div-->
        <div class="dropdown">
            <a href="help.html"><button class="dropbtn">How You Can Help</button></a>
            <div class="dropdown-content">
                <a href="donate.html">Donate</a>
                <a href="volunteer.html">Volunteer</a>
                <a href="intern.html">Intern</a>
            </div><!--dropdown-content close div-->
        </div><!--dropdown close div-->
        <div class="dropdown">
            <a href="contact.html"><button class="dropbtn">Contact</button></a>
            <div class="dropdown-content">
                <a href="email.html">Email</a>
                <a href="faqs.html">FAQS</a>
                <a href="newsletter.html">Newsletter</a>
            </div><!--dropdown-content-->
        </div><!--dropdown close div-->
    </div><!--container close div-->

移动主菜单后,我的悬停菜单出现问题。由于徽标,它所在的div比菜单div大。当我第一次编写菜单时,它位于div的顶部,悬停菜单显示正常。

我使用position绝对位置和相对位置将菜单div移动到父div的底部,将底部设置为0和右215px。之后,悬停菜单在主菜单上开始重叠。任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:1)

为了使徽标适应headers身高:

#logo2 {

  display: block;
  width: auto;
  height: auto;
  max-height: 108px;

}

您已将菜单容器设置为绝对位置,我已将其设置为内联,因此它不会停留在徽标上方: - 请从position: absolute;移除#container,然后添加以下内容:line-height: 108px;,使菜单垂直居中。

为了使徽标略小于标题本身,同时将其置于中心位置,我在#logo中添加了以下内容:

max-height: 70px;
margin: 19px 10px 19px 10px;

#header {
  height: 108px;
  width: 1140px;
  background-color: #faa220;
  position: relative;
}

#Logo2 {
  float: left;
  display: block;
  width: auto;
  height: auto;
  max-height: 70px;
  margin: 19px 10px 19px 10px;
}

#header links {
  height: 50px;
  float: left;
  list-style: none;
  padding-top: 10px;
}

#container {
  overflow: hidden;
  background-color: #faa220;
  font-family: Arial, Helvetica, sans-serif;
  bottom: 0;
  right: 215px;
  line-height: 108px;
}

.container a {
  float: left;
  font-size: 18px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  position: absolute;
}

.dropdown {
  float: left;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 18px;
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  cursor: pointer;
}

.container a:hover,
.dropdown:hover .dropbtn {
  background-color: #faa220;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #faa220;
  min-width: 100px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
  position: absolute;
}

.dropdown-content a {
  float: none;
  color: white;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
  position: absolute;
  bottom: 0;
}

.dropdown-content a:hover {
  background-color: #faa220;
  position: absolute;
  bottom: 0;
}

.dropdown:hover .dropdown-content {
  position: absolute;
  display: block;
  bottom: 0;
}
<div id="header">
  <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Coca-Cola_logo.svg/1200px-Coca-Cola_logo.svg.png" align="left" id="Logo2" />
  <div id="container">
    <div class="dropdown">
      <a href="index.html"><button class="dropbtn">Home</button></a>
    </div>
    <!--dropdown close div-->
    <div class="dropdown">
      <a href="about.html"><button class="dropbtn">About Us</button></a>
      <div class="dropdown-content">
        <a href="bio.html">Bio</a>
        <a href="news.html">News</a>
        <a href="partners.html">Partners</a>
      </div>
      <!--dropdown-content close div-->
    </div>
    <!--dropdown close div-->
    <div class="dropdown">
      <a href="awards.html"><button class="dropbtn">Awards/Certifications</button></a>
    </div>
    <div class="dropdown">
      <a href="services.html"><button class="dropbtn">Services</button></a>
      <div class="dropdown-content">
        <a href="solar.html">Solar</a>
        <a href="water.html">Water</a>
        <a href="housing.html">Housing</a>
        <a href="training.html">Training</a>
        <a href="broadband.html">Broadband</a>
      </div>
      <!--dropdown-content close div-->
    </div>
    <!--dropdown close div-->
    <div class="dropdown">
      <a href="help.html"><button class="dropbtn">How You Can Help</button></a>
      <div class="dropdown-content">
        <a href="donate.html">Donate</a>
        <a href="volunteer.html">Volunteer</a>
        <a href="intern.html">Intern</a>
      </div>
      <!--dropdown-content close div-->
    </div>
    <!--dropdown close div-->
    <div class="dropdown">
      <a href="contact.html"><button class="dropbtn">Contact</button></a>
      <div class="dropdown-content">
        <a href="email.html">Email</a>
        <a href="faqs.html">FAQS</a>
        <a href="newsletter.html">Newsletter</a>
      </div>
      <!--dropdown-content-->
    </div>
    <!--dropdown close div-->
  </div>
  <!--container close div-->

PS。我不知道菜单交互是什么,但你可能会知道它。

答案 1 :(得分:0)

解决了问题的一部分,并设法让下拉菜单实际显示每个项目在彼此之上。但是我没有找到如何把它的子菜单放在一边(如果这是你想要的?)并使菜单实际上放下 down 。希望这会让你走上正确的道路。

问题的部分来自htmlhtml属性。

position
overflow