活跃的最后悬停

时间:2013-09-13 11:24:17

标签: html css menu hover mouse

我只有HTML + CSS菜单。

https://dl.dropboxusercontent.com/u/73908828/ccs_help/home.html

<head>
  <style>
  *, body {
    padding:0px;
    margin: 0px;
    font-family: "Arial";
  }

  #line {
    position: absolute;
    height:62px;
    width: 100%;
    top: 408px;
    z-index:1;
    border-top: 1px solid #636363;
    border-bottom: 2px solid #393939;
    background-color: #0a0c0c;
    -webkit-box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 1);
    -moz-box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 1);
    box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 1);
  }
  #menu-box, #menu {
    width: 990px;
    display: block;
    margin-left: auto;
    margin-right: auto;
  }
  #menu {
    height:62px;
  }
  #menu ul.c {
    list-style-type: none;
  }

  #center ul a.c {
    font-size: 34px;
    font-weight: bold;
    line-height: 65px;
    letter-spacing: 0px;
    display: block;
    padding-left: 30px;
    padding-right: 30px;
    background-repeat: no-repeat;
    background-position: right;
    text-decoration: none;
    color: #505050;
  }
  #center ul a.c:hover {
    color: #038aff;
  }
  ul#nav {
    margin: 0;
    padding: 0;
    list-style: none;
  }
  ul#nav li {
    display: inline;
  }
  ul#nav li a {
    float: left;
    line-height: 40px;
    text-decoration: none;
  }
  ul#nav .current a, ul#nav li:hover > a {
    text-decoration: none;
  }
  ul#nav ul {
    display: none;
  }
  ul#nav li:hover > ul {
    position: absolute;
    display: block;
    margin: 65px 0 0 0;
    font-size: 14px;
    letter-spacing: 1px;
    color: #a4a4a4;
    float:left;
    left:50%;
    text-align:center;
  }
  ul#nav li:hover > ul li {
    position:relative;
    right:50%;
    display: table;
  }
  ul#nav li:hover > ul li a {
    float: left;
    text-decoration: none;
  }
  ul#nav li:hover > ul li a:hover {
    text-decoration: none;
    text-shadow: none;
  }
  .submenu {
    background-color: #000;
    display:table-cell;
    vertical-align: middle;
    border-bottom: 1px solid #393939;
    white-space: nowrap;
  }
  </style>
</head>
<body>
  <div id="line">
    <div id="menu-box">
      <div id="center">
        <ul id="nav" class="c">
          <li><a id="products" href="javascript:;" class="c" style="padding-left:0px;">PRODUCTS</a>
            <ul>
              <li class="outer">
                <div class="submenu-left"></div>
                <div class="submenu">SECOND_PRODUCTS</div>
                <div class="submenu-right"></div>
              </li>
            </ul>
          </li>
          <li><a href="MAIN_SUPPORT_URL" class="c">MAIN_SUPPORT</a>
            <ul>
              <li class="outer">
                <div class="submenu-left"></div>
                <div class="submenu">SECOND_SUPPORT</div>
                <div class="submenu-right"></div>
              </li>
            </ul>
          </li>
          <li><a id="sale" href="javascript:;" class="c" style="background-image: none; padding-right: 0px;">DISTRIBUTION</a>
            <ul>
              <li class="outer">
                <div class="submenu-left"></div>
                <div class="submenu">SECOND_DISTRIBUTION</div>
                <div class="submenu-right"></div>
              </li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
  </div>
  <div id="main">
    <div class="lgflags"><a href="?lang=en" class="en"></a><a href="?lang=de" class="de"></a></div>
    <div class="img"></div>
  </div>
</body>

我的问题是,我是如何制作的,以便即使没有鼠标悬停也会始终显示第二个菜单?我需要最后一个悬停菜单始终可见。

我只使用HTML和CSS,但如果需要,可以使用JavaScript或jQuery。

1 个答案:

答案 0 :(得分:0)

使用

将悬停样式应用到第二个菜单
nth-child(2)

例如,

ul#nav li:hover > ul, ul#nav li:nth-child(2)> ul {
    position: absolute;
    display: block;
    margin: 65px 0 0 0;
    font-size: 14px;
    letter-spacing: 1px;
    color: #a4a4a4;
    float:left;
    left:50%;
    text-align:center;
}