【问题标题】:Sub menu drop down in WordpressWordpress 中的子菜单下拉菜单
【发布时间】:2017-02-17 05:21:22
【问题描述】:

我隐藏了我的子菜单,并添加了 css 以在将鼠标悬停在父菜单项上时显示子菜单下拉菜单。

我想做的是在“单击”父菜单按钮而不是“悬停”时让子菜单下拉。

我的 CSS 是:

.sub-menu {
    display: none;
}

.shiftnav ul li:hover > ul {

display: block; /* show sub menus when hovering over a parent */

}

【问题讨论】:

    标签: php css wordpress navigation


    【解决方案1】:

    我做的和例子 这是 HTML 代码:

    #demo {
      margin: 30px 0 50px 0;
      font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
    }
    #demo .wrapper {
      display: inline-block;
      width: 180px;
      margin: 0 10px 0 0;
      height: 20px;
      position: relative;
    }
    #demo .parent {
      height: 100%;
      width: 100%;
      display: block;
      cursor: pointer;
      line-height: 30px;
      height: 30px;
      border-radius: 5px;
      background: #F9F9F9;
      border: 1px solid #AAA;
      border-bottom: 1px solid #777;
      color: #282D31;
      font-weight: bold;
      z-index: 2;
      position: relative;
      -webkit-transition: border-radius .1s linear, background .1s linear, z-index 0s linear;
      -webkit-transition-delay: .8s;
      text-align: center;
    }
    #demo .parent:hover,
    #demo .content:hover ~ .parent {
      background: #fff;
      -webkit-transition-delay: 0s, 0s, 0s;
    }
    #demo .content:hover ~ .parent {
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
      z-index: 0;
    }
    #demo .content {
      position: absolute;
      top: 0;
      display: block;
      z-index: 1;
      height: 0;
      width: 180px;
      padding-top: 30px;
      -webkit-transition: height .5s ease;
      -webkit-transition-delay: .4s;
      border: 1px solid #777;
      border-radius: 5px;
      box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
    }
    #demo .wrapper:active .content {
      height: 123px;
      z-index: 3;
      -webkit-transition-delay: 0s;
    }
    #demo .content:hover {
      height: 123px;
      z-index: 3;
      -webkit-transition-delay: 0s;
    }
    #demo .content ul {
      background: #fff;
      margin: 0;
      padding: 0;
      overflow: hidden;
      height: 100%;
      border-bottom-left-radius: 5px;
      border-bottom-right-radius: 5px;
    }
    #demo .content ul a {
      text-decoration: none;
    }
    #demo .content li:hover {
      background: #eee;
      color: #333;
    }
    #demo .content li {
      list-style: none;
      text-align: left;
      color: #888;
      font-size: 14px;
      line-height: 30px;
      height: 30px;
      padding-left: 10px;
      border-top: 1px solid #ccc;
    }
    #demo .content li:last-of-type {
      border-bottom-left-radius: 5px;
      border-bottom-right-radius: 5px;
    }
    <div id="demo">
      <div class="wrapper">
        <div class="content">
          <ul>
            <a href="#">
              <li>Lorem ipsum dolor</li>
            </a>
            <a href="#">
              <li>Consectetur adipisicing</li>
            </a>
            <a href="#">
              <li>Reprehenderit</li>
            </a>
            <a href="#">
              <li>Commodo consequat</li>
            </a>
          </ul>
        </div>
        <div class="parent">Drop Down Parent 1</div>
      </div>
    
      <div class="wrapper">
        <div class="content">
          <ul>
            <a href="#">
              <li>Lorem ipsum dolor</li>
            </a>
            <a href="#">
              <li>Consectetur adipisicing</li>
            </a>
            <a href="#">
              <li>Reprehenderit</li>
            </a>
            <a href="#">
              <li>Commodo consequat</li>
            </a>
          </ul>
        </div>
        <div class="parent">Drop Down Parent 2</div>
      </div>

    【讨论】:

    • 非常感谢。我很难将您的示例应用到我的菜单中。我试过了:.shiftnav-nav .shiftnav-target { display: block; }"shiftnav-target 是partent"
    【解决方案2】:

    您可以使用li a:first-child:nth-last-child(x) { } 实现几乎相同的效果。

    这是quick example。标记只是您的标准嵌套 UL,但请注意,我在 HTML 中只使用了一个类,位于根 &lt;ul&gt;。自己测试一下,在任何级别添加任意数量的嵌套列表!

    【讨论】:

    • 谢谢你。我在使用菜单中的示例时遇到了困难。我尝试将我的 css 更改为:`.shiftnav li a:first-child:nth-last-child(x) { display: block; }~
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    • 2011-07-20
    • 2012-10-15
    • 1970-01-01
    相关资源
    最近更新 更多