断点后响应式导航栏的问题

时间:2018-12-30 10:58:29

标签: menu navigation media-queries responsive

以下代码有两个问题:

  1. 在420断点之后,我的第二级子菜单没有出现(例如第1.1页(“ Seite 1.1”)或第4.2页(“ Seite 4.2”)等)。

  2. 触摸设备上没有“悬停”。通过单击第4页(“站点4”),<a href>将我重定向到(例如)seite4.html。这是我的主要问题。通过单击第4页(“ Seite 4”),您应该看到子菜单4.1和4.2。然后在第4页(“网站4”)上单击两次,应将我重定向到seite4.html

首次点击:->打开子菜单
第二次单击:-> seite4.html

有人知道如何添加“ DoubleClick”功能吗?
如果可能的话,不使用JavaScript。

body {
    width: 100vw;
    height: auto;
    overflow-x: hidden;
}

#nav
{
    width: 1500px;
    height: 50px;
    margin: auto;
    background-color: #EDEDED;
}

#nav > a
    {
        display: none;
    }

#nav li
    {
        position: relative;
        width: 187.5px;
    }

#nav ul {
    text-decoration: none;
    
}

#nav li a {
    color: black;
    display: block;
}

#nav li a:active {
    background-color: #c00 !important;
}

#nav span:after{
    width: 0;
    height: 0;
    border: 0.313em solid transparent; /* 5 */
    border-bottom: none;
    border-top-color: black;
    content: '';
    vertical-align: middle;
    display: inline-block;
    position: relative;
    right: -0.313em; /* 5 */
}
 
/* first level */
 
#nav > ul {
    height: 50px;
    background-color: #EDEDED;;
}

#nav > ul > li {
    width: 187.5px;
    height: 50px;
    float: left;
    list-style: none;
}

#nav > ul > li > a {
    height: 50px;
    font-size: 0.9vw; /* 24 */
    line-height: 2.5vw; /* 60 (24) */
    text-align: center;
    text-decoration: none;
}

#nav > ul > li:not( :last-child ) > a {
    border-right: 0px solid black;
}

#nav > ul > li:hover > a,
#nav > ul:not( :hover ) > li.active > a {
    background-color: lightcoral;
}
 
/* second level */
 
#nav li ul {
    display: none;
    position: absolute;
    top: 100%;
    background-color: #EDEDED;
    list-style: none;
}

#nav li:hover ul {
    display: block;
    left: 0;
    right: 0;
}

#nav li:not( :first-child ):hover ul {
    left: 0;
}

#nav li ul a {
    font-size: 0.9vw;
    border-top: 0.05vw solid lightcoral;
    height: auto;
    line-height: 2.5vw;
    text-align: center;
    text-decoration: none;
}

#nav li ul li a:hover,
#nav li ul:not( :hover ) li.active a {
    background-color: lightcoral;
}

/******************************************* 1500 *******************************************/
@media only screen and (max-width: 1500px) {

    #nav  {
        width: 90vw;
        height: 3.2vw;
    }

    #nav li {
        position: relative;
        width: 11.25vw;
    } 

    #nav span:after{
        width: 0;
        height: 0;
        border: 0.3vw solid transparent; /* 5 / 0.313em */
        border-bottom: none;
        border-top-color: black;
        content: '';
        vertical-align: middle;
        display: inline-block;
        position: relative;
        right: -0.3vw; /* 5 / -0.313em */
    }
 
/* first level */
 
    #nav > ul {
        height: 3.2vw;
        background-color: #EDEDED;
    }

#nav > ul > li {
    width: 11.25vw;
    height: 3.2vw;
    float: left;
    list-style: none;
}

#nav > ul > li > a {
    height: 3.2vw;
    font-size: 1vw; /* 24 */
    line-height: 3.1vw; /* 60 (24) */
}

#nav > ul > li:hover > a,
#nav > ul:not( :hover ) > li.active > a {
    background-color: lightcoral;
}
 
/* second level */
 
#nav li ul {
    display: none;
    position: absolute;
    background-color: #EDEDED;
}

#nav li:not( :first-child ):hover ul {
    left: 0;
}

#nav li ul a {
    font-size: 0.9vw;
    border-top: 0.05vw solid lightcoral;
    height: auto;
    line-height: 3.2vw;
    text-align: center;
    text-decoration: none;
}

#nav li ul li a:hover,
#nav li ul:not( :hover ) li.active a {
    background-color: lightcoral;
}
 
}

/******************************************* 420 *******************************************/
@media screen and (max-width: 420px) {
    body {
    width: 100vw;
  }
    
    #nav {
        width: 100vw;
        height: 14vw;
    }
    
    #nav li {
        width: 100vw;
    }
    
    #nav span:after{
        border: 1.5vw solid transparent; /* 5 / 0.313em */
        border-bottom: none;
        border-top-color: black;
        content: '';
        vertical-align: middle;
        display: inline-block;
        position: relative;
        right: -3vw; /* 5 / -0.313em */
    }
    
    #nav > a {
        width: 14vw; /* 50 BUTTON*/
        height: 14vw; /* 50 BUTTON */
        text-align: left;
        text-indent: -9999px;
        background-color: lightcoral;
        position: relative;
    }
    
    #nav > a:before,
    #nav > a:after {
        position: absolute;
        border: 0.7vw solid black; /** BUTTON COLOUR **/
        top: 35%;
        left: 25%;
        right: 25%;
        content: '';
    }

    #nav > a:after {
        top: 60%;
    }

    #nav:not( :target ) > a:first-of-type,
    #nav:target > a:last-of-type {
        display: block;
    }

/* first level */

    #nav > ul {
        height: auto;
        display: none;
        position: absolute;
        left: 0;
        right: 0;
    }

    #nav:target > ul {
        display: block;
    }

    #nav > ul > li {
        width: 100%;
        height: 14vw;
        float: none;
    }
    
    #nav > ul > li > a {
        height: auto;
        text-align: left;
        font-size: 5vw;
        padding-top: 6vw; /* 20 (24) */
        padding-bottom: 5vw;
        padding-left: 2vw;
        box-sizing: border-box;
    }
    
    #nav > ul > li:not( :last-child ) > a {
        border-right: none;
        border-bottom: 0.1vw solid lightcoral;
    }


/* second level */
    
    #nav li ul {
        position: static;
        height: auto;
        padding: 5vw; /* 20 */
        padding-top: 0;
    }
    
    #nav li ul a {
        width: 100vw;
        height: 14vw;
        font-size: 5vw;
    }
}
<body>
  <nav id="nav" role="navigation">
          <a href="#nav" title="Show navigation">Show navigation</a>
          <a href="#" title="Hide navigation">Hide navigation</a>
          <ul>
              <li class="active"><a href="index.html">Startseite</a></li>
              <li>
                  <a href="/" aria-haspopup="true"><span>Seite 1</span></a>
                  <ul>
                      <li><a href="/">Seite 1.1</a></li>
                      <li><a href="/">Seite 1.2</a></li>
                  </ul>
              </li>
              <li><a href="index.html">Seite 2</a></li>
              <li><a href="index.html">Seite 3</a></li>
              <li>
                  <a href="/" aria-haspopup="true"><span>Seite 4</span></a>
                  <ul>
                      <li><a href="/">Seite 4.1</a></li>
                      <li><a href="/">Seite 4.2</a></li>
                      <li><a href="/">Seite 4.3</a></li>
                  </ul>
              </li>
              <li><a href="index.html">Seit 5</a></li>
              <li>
                  <a href="/" aria-haspopup="true"><span>Seite 6</span></a>
                  <ul>
                      <li><a href="/">Seite 6.1</a></li>
                      <li><a href="/">Seite 6.2</a></li>
                  </ul>
              </li>
              <li><a href="/">Seite 7</a></li>
          </ul>
      </nav>
 </body>

0 个答案:

没有答案