第三个下拉菜单未显示在移动设备调整大小上

时间:2017-11-04 10:42:44

标签: html css

我无法弄清楚为什么我的第三个下拉菜单无效,前两个下拉菜单在桌面设备,平板电脑和移动设备上大小调整,但第三个下拉菜单仅适用于桌面,但不适用于移动。任何帮助将不胜感激。这是我的导航菜单HTML代码:

.toggle,
[id^=drop] {
  display: none;
}

/* Giving a background-color to the nav container. */
nav { 
  margin:0;
  padding: 0;
  background-color: #000000;
}

/* Since we'll have the "ul li" "float:left"
* we need to add a clear after the container. */

nav:after {
  content:"";
  display:table;
  clear:both;
}

/* Removing padding, margin and "list-style" from the "ul",
* and adding "position:reltive" */
nav ul {
  display: flex;
  justify-content: center;
  padding:0;
  margin:0;
  list-style: none;
  position: relative;
}

/* Positioning the navigation items inline */
nav ul li {
  margin: 0px;
  display:inline-block;
  float: left;
  background-color: #000000;
}

/* Styling the links */
nav a {
  display:block;
  padding:14px 20px;  
  color:#FFF;
  font-size:17px;
  text-decoration:none;
  line-height: 32px;
}

nav ul li ul li:hover { background: #000000; }

/* Background color change on Hover */
nav a:hover { 
  background-color: #FFC213; 
}

/* Hide Dropdowns by Default
* and giving it a position of absolute */
nav ul ul {
  display: none;
  position: absolute; 
  /* has to be the same number as the "line-height" of "nav a" */
  top: 60px; 
}

/* Display Dropdowns on Hover */
nav ul li:hover > ul {
  display:inherit;
  z-index: 3;
}

/* Fisrt Tier Dropdown */
nav ul ul li {
  width:170px;
  float:none;
  display:list-item;
  position: relative;
}

/* Second, Third and more Tiers 
* We move the 2nd and 3rd etc tier dropdowns to the left
* by the amount of the width of the first tier.
*/
nav ul ul ul li {
  position: relative;
  top:-60px;
  /* has to be the same number as the "width" of "nav ul ul li" */ 
  left:170px; 
}

/* Change ' +' in order to change the Dropdown symbol */
li > a:after { content:  ' +'; }
li > a:only-child:after { content: ''; }

/* Media Queries
--------------------------------------------- */
@media all and (max-width : 768px) {
  nav {
      margin: 0;
  }
  /* Hide the navigation menu by default */
  /* Also hide the  */
  .toggle + a,
  .menu {
      display: none;
  }
  /* Stylinf the toggle lable */
  .toggle {
      display: block;
      background-color: #000000;
      padding:14px 20px;  
      color:#FFF;
      font-size:17px;
      text-decoration:none;
      border:none;
  }
  .toggle:hover {
      background-color: #FFC213;
  }
  /* Display Dropdown when clicked on Parent Lable */
  [id^=drop]:checked + ul {
      display: block;
  }
  /* Change menu item's width to 100% */
  nav ul li {
      display: block;
      width: 100%;
  }
  nav ul ul .toggle,
  nav ul ul a {
      padding: 0 40px;
  }
  nav ul ul ul a {
      padding: 0 80px;
  }
  nav a:hover,
  nav ul ul ul a {
      background-color: #FFC213;
  }
  nav ul li ul li .toggle,
  nav ul ul a,
  nav ul ul ul a{
      padding:14px 20px;  
      color:#FFF;
      font-size:17px; 
  }
  nav ul li ul li .toggle,
  nav ul ul a {
      background-color: #212121; 
  }
  /* Hide Dropdowns by Default */
  nav ul ul {
      float: none;
      position:static;
      color: #ffffff;
      /* has to be the same number as the "line-height" of "nav a" */
  }
  /* Hide menus on hover***********effect changes on mobile review */
  nav ul ul li:hover > ul,
  nav ul li:hover > ul {
      display: none;
       /*****mobile dorpdown code*********z-index:0;***********/
  }
  /* Fisrt Tier Dropdown */
  nav ul ul li {
      display: block;
      width: 100%;
  }
  nav ul ul ul li {
      position: static;
      /* has to be the same number as the "width" of "nav ul ul li" */ 
  }
}

@media all and (max-width : 150px) {
  nav ul li {
      display:block;
      width: 94%;
  }
}
<nav>
    <label for="drop" class="toggle">Menu</label>
    <input type="checkbox" id="drop" />
    <ul class="menu">
        <li><a href="index.html">Home</a></li>
        <li>
            <!-- First Tier Drop Down -->
            <label for="drop-1" class="toggle">About Us +</label>
            <a href="About us.html">About Us</a>
            <input type="checkbox" id="drop-1" />
            <ul>
                <li><a href="methodology">Methodology</a></li>
            </ul>
        </li>
        <li><a href="service.html">Services</a></li>
        <li>
            <!-- First Tier Drop Down -->
            <label for="drop-2" class="toggle">List of Courses +</label>
            <a href="#">List of Courses</a>
            <input type="checkbox" id="drop-2" />
            <ul>
                <li><a href="administration.html">Administration</a></li>
                <li><a href="agriculture.html">Agriculture</a></li>
            </ul>
        </li>
        <li>
            <!-- First Tier Drop Down -->
            <label for="drop-2" class="toggle">Ongoing Courses +</label>
            <a href="#">Ongoing Courses</a>
            <input type="checkbox" id="drop-2" />
            <ul>
                <li><a href="creative.html">Creative</a></li>
                <li><a href="enterprise.html">Enterprise</a></li>
                <li><a href="microsoft_office.html">Microsoft excel</a></li>
                <li><a href="Hardware.html">Hardware</a></li>
                <li><a href="management.html">Management</a></li>
                <li><a href="microsoft_office.html">Microsoft Office</a></li>
                <li><a href="networking.html">Networking</a></li>
                <li><a href="webdesign.html">Web design</a></li>
                <li><a href="webdev.html">Web development</a></li>
            </ul>
        </li>
        <li><a href="events.html">Events</a></li>
        <li><a href="contact.html">Contact</a></li>
        <li>
            <a href="#"><img src="images/soc/facebook1.png" height="32" width="32"></a>
        </li>
        <li>
            <a href="#"><img src="images/soc/twitter1.png" height="32" width="32"></a>
        </li>
        <li>
            <a href="#"><img src="images/soc/instagram1.png" height="32" width="34"></a>
        </li>
    </ul>
</nav>

1 个答案:

答案 0 :(得分:0)

您正在使用&#34; drop-2&#34;对于第二次和第三次下拉。对于第三个菜单,将其更改为for="drop-3"id="drop-3",它将起作用。

&#13;
&#13;
.toggle,
[id^=drop] {
  display: none;
}
/* Giving a background-color to the nav container. */
nav { 
  margin:0;
  padding: 0;
  background-color: #000000;
}
/* Since we'll have the "ul li" "float:left"
* we need to add a clear after the container. */
nav:after {
  content:"";
  display:table;
  clear:both;
}
/* Removing padding, margin and "list-style" from the "ul",
* and adding "position:reltive" */
nav ul {
  display: flex;
  justify-content: center;
  padding:0;
  margin:0;
  list-style: none;
  position: relative;
}
/* Positioning the navigation items inline */
nav ul li {
  margin: 0px;
  display:inline-block;
  float: left;
  background-color: #000000;
}
/* Styling the links */
nav a {
  display:block;
  padding:14px 20px;  
  color:#FFF;
  font-size:17px;
  text-decoration:none;
  line-height: 32px;
}
nav ul li ul li:hover { background: #000000; }
/* Background color change on Hover */
nav a:hover { 
  background-color: #FFC213; 
}
/* Hide Dropdowns by Default
* and giving it a position of absolute */
nav ul ul {
  display: none;
  position: absolute; 
  /* has to be the same number as the "line-height" of "nav a" */
  top: 60px; 
}
/* Display Dropdowns on Hover */
nav ul li:hover > ul {
  display:inherit;
  z-index: 3;
}
/* Fisrt Tier Dropdown */
nav ul ul li {
  width:170px;
  float:none;
  display:list-item;
  position: relative;
}
/* Second, Third and more Tiers 
* We move the 2nd and 3rd etc tier dropdowns to the left
* by the amount of the width of the first tier.
*/
nav ul ul ul li {
  position: relative;
  top:-60px;
  /* has to be the same number as the "width" of "nav ul ul li" */ 
  left:170px; 
}
/* Change ' +' in order to change the Dropdown symbol */
li > a:after { content:  ' +'; }
li > a:only-child:after { content: ''; }

/* Media Queries
--------------------------------------------- */
@media all and (max-width : 768px) {
  nav {
      margin: 0;
  }
  /* Hide the navigation menu by default */
  /* Also hide the  */
  .toggle + a,
  .menu {
      display: none;
  }
  /* Stylinf the toggle lable */
  .toggle {
      display: block;
      background-color: #000000;
      padding:14px 20px;  
      color:#FFF;
      font-size:17px;
      text-decoration:none;
      border:none;
  }
  .toggle:hover {
      background-color: #FFC213;
  }
  /* Display Dropdown when clicked on Parent Lable */
  [id^=drop]:checked + ul {
      display: block;
  }
  /* Change menu item's width to 100% */
  nav ul li {
      display: block;
      width: 100%;
  }
  nav ul ul .toggle,
  nav ul ul a {
      padding: 0 40px;
  }
  nav ul ul ul a {
      padding: 0 80px;
  }
  nav a:hover,
  nav ul ul ul a {
      background-color: #FFC213;
  }
  nav ul li ul li .toggle,
  nav ul ul a,
  nav ul ul ul a{
      padding:14px 20px;  
      color:#FFF;
      font-size:17px; 
  }
  nav ul li ul li .toggle,
  nav ul ul a {
      background-color: #212121; 
  }
  /* Hide Dropdowns by Default */
  nav ul ul {
      float: none;
      position:static;
      color: #ffffff;
      /* has to be the same number as the "line-height" of "nav a" */
  }
  /* Hide menus on hover***********effect changes on mobile review */
  nav ul ul li:hover > ul,
  nav ul li:hover > ul {
      display: none;
       /*****mobile dorpdown code*********z-index:0;***********/
  }
  /* Fisrt Tier Dropdown */
  nav ul ul li {
      display: block;
      width: 100%;
  }
  nav ul ul ul li {
      position: static;
      /* has to be the same number as the "width" of "nav ul ul li" */ 
  }
}

@media all and (max-width : 150px) {
  nav ul li {
      display:block;
      width: 94%;
  }
}
&#13;
<nav>
    <label for="drop" class="toggle">Menu</label>
    <input type="checkbox" id="drop" />
    <ul class="menu">
        <li><a href="index.html">Home</a></li>
        <li>
            <!-- First Tier Drop Down -->
            <label for="drop-1" class="toggle">About Us +</label>
            <a href="About us.html">About Us</a>
            <input type="checkbox" id="drop-1" />
            <ul>
                <li><a href="methodology">Methodology</a></li>
            </ul>
        </li>
        <li><a href="service.html">Services</a></li>
        <li>
            <!-- First Tier Drop Down -->
            <label for="drop-3" class="toggle">List of Courses +</label>
            <a href="#">List of Courses</a>
            <input type="checkbox" id="drop-3" />
            <ul>
                <li><a href="administration.html">Administration</a></li>
                <li><a href="agriculture.html">Agriculture</a></li>
            </ul>
        </li>
        <li>
            <!-- First Tier Drop Down -->
            <label for="drop-2" class="toggle">Ongoing Courses +</label>
            <a href="#">Ongoing Courses</a>
            <input type="checkbox" id="drop-2" />
            <ul>
                <li><a href="creative.html">Creative</a></li>
                <li><a href="enterprise.html">Enterprise</a></li>
                <li><a href="microsoft_office.html">Microsoft excel</a></li>
                <li><a href="Hardware.html">Hardware</a></li>
                <li><a href="management.html">Management</a></li>
                <li><a href="microsoft_office.html">Microsoft Office</a></li>
                <li><a href="networking.html">Networking</a></li>
                <li><a href="webdesign.html">Web design</a></li>
                <li><a href="webdev.html">Web development</a></li>
            </ul>
        </li>
        <li><a href="events.html">Events</a></li>
        <li><a href="contact.html">Contact</a></li>
        <li>
            <a href="#"><img src="images/soc/facebook1.png" height="32" width="32"></a>
        </li>
        <li>
            <a href="#"><img src="images/soc/twitter1.png" height="32" width="32"></a>
        </li>
        <li>
            <a href="#"><img src="images/soc/instagram1.png" height="32" width="34"></a>
        </li>
    </ul>
</nav>
&#13;
&#13;
&#13;

相关问题