首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >第三个下拉菜单在移动调整大小时不显示

第三个下拉菜单在移动调整大小时不显示
EN

Stack Overflow用户
提问于 2017-11-04 18:42:44
回答 1查看 30关注 0票数 0

我不明白为什么我的第三个下拉菜单不起作用,前两个下拉菜单在桌面、平板电脑和移动设备上都可以完美地调整大小,但第三个下拉菜单只在桌面上有效,而在移动设备上不起作用。任何帮助都将不胜感激thanks.This是我的导航菜单html代码:

代码语言:javascript
复制
.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%;
  }
}
代码语言:javascript
复制
<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>

EN

回答 1

Stack Overflow用户

发布于 2017-11-04 18:49:45

您在第二个和第三个下拉列表中都使用了"drop-2“。在第三个菜单中将其更改为for="drop-3"id="drop-3",它将起作用。

代码语言:javascript
复制
.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%;
  }
}
代码语言:javascript
复制
<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>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47109847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档