悬停图像上的下拉菜单

时间:2016-11-04 05:53:25

标签: html css

W3Schools

您好,

我一直在尝试根据悬停在图像功能上整合下拉菜单。我去了上面的网站给出了一个例子,但我无法弄明白。以下是我目前的HTML。我希望将鼠标悬停在功能上的图像上有一个下拉菜单是Logo.png文件。我根本无法弄清楚如何将其集成到我的代码中。任何方向或帮助将不胜感激。

::-webkit-scrollbar {
  display: none;
}
body {
  margin: 0;
  background-color: #808080;
}
#menu {
  position: fixed;
  width: 100%;
  height: 140px;
  background-color: #555555;
}
#logopic {
  height: 100px;
  width: 140px;
}
#logo {
  float: left;
  margin: 1%;
  width: 160px;
}
.menuoptions {
  border: 1px solid white;
  border-radius: 50px;
  padding: 14px;
  float: left;
  letter-spacing: 2px;
  list-style-type: none;
  color: #FFFFFF;
  margin-top: 30px;
  margin-left: 45px;
  font-size: 125%;
  font-weight: bold;
}
.menuoptions:hover {
  color: #00b9f1;
  background-color: #FFFFFF;
}
#topsection {
  padding-top: 150px;
}
ul li {
  list-style-position: inside;
}
<div id="menu">

  <div id="logodiv">
    <a href="index.html">
      <img id="logo" src="images/Logo.png">
    </a>
  </div>

  <div id="menulinks">

    <ul id="options">
      <a href="#income">
        <li class="menuoptions">INCOME</li>
      </a>
      <a href="#expenses">
        <li class="menuoptions">EXPENSES</li>
      </a>
      <a href="#incomedistribution">
        <li class="menuoptions">INCOME DISTRIBUTION</li>
      </a>
      <a href="#spending">
        <li class="menuoptions">SPENDING</li>
      </a>
      <a href="#sidemenu">
        <li class="menuoptions">SIDE MENU</li>
      </a>
    </ul>

  </div>

</div>

2 个答案:

答案 0 :(得分:0)

使用sibligns选择器&#34; +&#34;

&#13;
&#13;
::-webkit-scrollbar {
  display: none;
}
body {
  margin: 0;
  background-color: #808080;
}
#menu {
  position: fixed;
  width: 100%;
  height: 140px;
  background-color: #555555;
}
#logopic {
  height: 100px;
  width: 140px;
}
#logo {
  float: left;
  margin: 1%;
  width: 160px;
}
.menuoptions {
  border: 1px solid white;
  border-radius: 50px;
  padding: 14px;
  float: left;
  letter-spacing: 2px;
  list-style-type: none;
  color: #FFFFFF;
  margin-top: 30px;
  margin-left: 45px;
  font-size: 125%;
  font-weight: bold;
}
.menuoptions:hover {
  color: #00b9f1;
  background-color: #FFFFFF;
}
#topsection {
  padding-top: 150px;
}
ul li {
  list-style-position: inside;
}

#menulinks {
  display: none;
}

#logodiv:hover + #menulinks {
  display: block
}
&#13;
<div id="menu">

  <div id="logodiv">
    <a href="index.html">
      <img id="logo" src="images/Logo.png">
    </a>
  </div>

  <div id="menulinks">

    <ul id="options">
      <a href="#income">
        <li class="menuoptions">INCOME</li>
      </a>
      <a href="#expenses">
        <li class="menuoptions">EXPENSES</li>
      </a>
      <a href="#incomedistribution">
        <li class="menuoptions">INCOME DISTRIBUTION</li>
      </a>
      <a href="#spending">
        <li class="menuoptions">SPENDING</li>
      </a>
      <a href="#sidemenu">
        <li class="menuoptions">SIDE MENU</li>
      </a>
    </ul>

  </div>

</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

Germano Plebani&gt;我相信它不会起作用,因为当你停止悬停徽标时,菜单会再次消失。

我改变了你的代码以使其更简单(至少在我看来):

<div id="menu">
<ul>
    <li id="logo"><img src="your_path"></li>
    <li class="menuoptions">INCOME</li>
    <li class="menuoptions">EXPENSES</li>
    <li class="menuoptions">INCOME DISTRIBUTION</li>
    <li class="menuoptions">SPENDING</li>
    <li class="menuoptions">SIDE MENU</li>
</ul>

    ::-webkit-scrollbar {
  display: none;
}
body {
  margin: 0;
  background-color: #808080;
}
#menu {
  position: fixed;
  width: 100%;
  height: 140px;
  background-color: #555555;
}
#logo {
  height:140px;
}

#logo img{
  width:160px;
}
ul{
  height:inherit;
  width:160px; /* Your menu has the size of your logo */
}

ul:hover {
  width:auto; /* when you hover your menu, it will take 100% of the width of it's container */
}
ul li {
    float: left;
    list-style:none;
}
ul:hover .menuoptions {
  display:block;
}
.menuoptions {
  border: 1px solid white;
  border-radius: 50px;
  padding: 14px;
  letter-spacing: 2px;
  list-style-type: none;
  color: #FFFFFF;
  margin-top: 30px;
  margin-left: 45px;
  font-size: 125%;
  font-weight: bold;
  display:none;
}
.menuoptions:hover {
  color: #00b9f1;
  background-color: #FFFFFF;
}

我也没有进行优化,但效果很好。