HTML / CSS导航栏项目在窗口大小调整时消失

时间:2014-07-02 14:28:15

标签: html css html5 css3

我在HTML / CSS中有一个相对简单的菜单栏。一切似乎都运行正常,但当浏览器窗口足够窄时,导航栏上的所有项目都会消失!我不确定代码的哪一部分正在做这个 - 我已经搞乱了CSS尝试修复它,但到目前为止我还没有运气。非常欢迎任何指示或建议!

http://www.tomstarley.com/website/accord/pages/home.php上的问题示例 - 尝试缩小范围!

HTML

<head>
<link rel="stylesheet" type="text/css" href="../css/navbar.css">
<link rel="stylesheet" type="text/css" href="../css/default.css">
</head>
<body>
<div id='cssmenu'>
<ul>
   <li><a href='home.php'><span>Home</span></a></li>
   <li class='has-sub'><a href='aboutus.php'><span>About Us</span></a>
      <ul>
         <li><a href='aboutus_ethos.php'><span>Ethos</span></a>
         </li>
         <li><a href='aboutus_mediator.php'><span>Mediator</span></a>
         </li>
    <li><a href='aboutus_testimonials.php'><span>Testimonials</span></a>
         </li>
      </ul>
   </li>
   <li class='has-sub'><a href='mediation.php'><span>Mediation</span></a>
<ul>
         <li><a href='mediation_whatismediation.php'><span>What is Mediation?</span></a>
         </li>
         <li><a href='mediation_howdoesitwork.php'><span>How does it work?</span></a>
         </li>
        <li><a href='mediation_divorce.php'><span>Divorce</span></a>
         </li>
         <li><a href='mediation_cohabitants.php'><span>Cohabitants</span></a>
         </li>
         <li><a href='mediation_children.php'><span>Children</span></a>
         </li>
        <li><a href='mediation_finance.php'><span>Finance</span></a>
         </li>
      </ul>
</li>
   <li class='has-sub'><a href='costs.php'><span>Costs</span></a>
<ul>
         <li><a href='costs_fees.php'><span>Fees</span></a>
         </li>
    <li><a href='costs_packages.php'><span>Packages</span></a>
         </li>
</ul>
</li>
<li><a href='faqs.php'><span>FAQs</span></a></li>
<li class='last'><a href='links.php'><span>Links</span></a></li>
</ul>
</div>
</body>

CSS

#cssmenu {
  position: relative;
  height: 22px;
  background: #009ACD;
  width: 100%;
}
#cssmenu ul {
  list-style: none;
  padding: 0;
  margin: 0;
  line-height: 1;
}
#cssmenu > ul {
  position: relative;
  display: block;
  background: #009ACD;
  height: 32px;
  width: auto;
  z-index: 500;
}
#cssmenu > ul > li {
  display: block;
  position: relative;
  float: left;
  margin: 0;
  padding: 0;
}
#cssmenu > ul > #menu-button {
  display: none;
}

#cssmenu ul li a {
  display: block;
  font-family: Helvetica, sans-serif;
  text-decoration: none;
}
#cssmenu > ul > li > a {
  font-size: 14px;
  font-weight: bold;
  padding: 15px 20px;
  color: #FFFFFF;
  text-transform: uppercase;
  -webkit-transition: color 0.25s ease-out;
  -moz-transition: color 0.25s ease-out;
  -ms-transition: color 0.25s ease-out;
  -o-transition: color 0.25s ease-out;
  transition: color 0.25s ease-out;
}
#cssmenu > ul > li.has-sub > a {
  padding-right: 32px;
}
#cssmenu > ul > li:hover > a {
  color: #000000;
}
#cssmenu li.has-sub::after {
  display: block;
  content: '';
  position: absolute;
  width: 0;
  height: 0;
}
#cssmenu > ul > li.has-sub::after {
  right: 10px;
  top: 20px;
  border: 5px solid transparent;
  border-top-color: #FFFFFF;
}
#cssmenu > ul > li:hover::after {
  border-top-color: #000000;
}
#indicatorContainer {
  position: absolute;
  height: 12px;
  width: 100%;
  bottom: 0px;
  overflow: hidden;
  z-index: -1;
}
#pIndicator {
  position: absolute;
  height: 0;
  width: 100%;
  border: 12px solid transparent;
  border-top-color: #2b2f3a;
  z-index: -2;
  -webkit-transition: left .25s ease;
  -moz-transition: left .25s ease;
  -ms-transition: left .25s ease;
  -o-transition: left .25s ease;
  transition: left .25s ease;
}
#cIndicator {
  position: absolute;
  height: 0;
  width: 100%;
  border: 12px solid transparent;
  border-top-color: #2b2f3a;
  top: -12px;
  right: 100%;
  z-index: -2;
}
#cssmenu ul ul {
  position: absolute;
  left: -9999px;
  top: 70px;
  opacity: 0;
  -webkit-transition: opacity .3s ease, top .25s ease;
  -moz-transition: opacity .3s ease, top .25s ease;
  -ms-transition: opacity .3s ease, top .25s ease;
  -o-transition: opacity .3s ease, top .25s ease;
  transition: opacity .3s ease, top .25s ease;
  z-index: 1000;
}
#cssmenu ul ul ul {
  top: 37px;
  padding-left: 5px;
}
#cssmenu ul ul li {
  position: relative;
}
#cssmenu > ul > li:hover > ul {
  left: auto;
  top: 44px;
  opacity: 1;
}
#cssmenu ul ul li:hover > ul {
  left: 170px;
  top: 0;
  opacity: 1;
}
#cssmenu ul ul li a {
  width: 130px;
  border-bottom: 1px solid #eee;
  padding: 10px 20px;
  font-size: 12px;
  color: #FFFFFF;
  background: #009ACD;
  -webkit-transition: all .35s ease;
  -moz-transition: all .35s ease;
  -ms-transition: all .35s ease;
  -o-transition: all .35s ease;
  transition: all .35s ease;
}
#cssmenu ul ul li:hover > a {
  background: #f6f6f6;
  color: #000000;
}
#cssmenu ul ul li:last-child > a,
#cssmenu ul ul li.last > a {
  border-bottom: 0;
}
.submenuArrow {
  border: 6px solid transparent;
  width: 0;
  height: 0;
  border-bottom-color: #fff;
  position: absolute;
  top: -12px;
}
#cssmenu ul ul li.has-sub::after {
  border: 4px solid transparent;
  border-left-color: #9ea2a5;
  right: 10px;
  top: 12px;
  -moz-transition: all .2s ease;
  -ms-transition: all .2s ease;
  -o-transition: all .2s ease;
  transition: all .2s ease;
  -webkit-transition: -webkit-transform 0.2s ease, right 0.2s ease;
}
#cssmenu ul ul li.has-sub:hover::after {
  border-left-color: #fff;
  right: -5px;
  -webkit-transform: rotateY(180deg);
  -ms-transform: rotateY(180deg);
  -moz-transform: rotateY(180deg);
  -o-transform: rotateY(180deg);
  transform: rotateY(180deg);
}
@media all and (max-width: 800px), only screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min--moz-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (-o-min-device-pixel-ratio: 2/1) and (max-width: 1024px), only screen and (min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min-resolution: 192dpi) and (max-width: 1024px), only screen and (min-resolution: 2dppx) and (max-width: 1024px) {
  #cssmenu {
    width: auto;
  }
  #cssmenu ul {
    width: auto;
  }
  #cssmenu .submenuArrow,
  #cssmenu #indicatorContainer {
    display: none;
  }
  #cssmenu > ul {
    height: auto;
    display: block;
  }
  #cssmenu > ul > li {
    float: none;
  }
  #cssmenu li,
  #cssmenu > ul > li {
    display: none;
  }
  #cssmenu ul ul,
  #cssmenu ul ul ul,
  #cssmenu ul > li:hover > ul,
  #cssmenu ul ul > li:hover > ul {
    position: relative;
    left: auto;
    top: auto;
    opacity: 1;
    padding-left: 0;
  }
  #cssmenu ul .has-sub::after {
    display: none;
  }
  #cssmenu ul li a {
    padding: 12px 20px;
  }
  #cssmenu ul ul li a {
    border: 0;
    background: none;
    width: auto;
    padding: 8px 35px;
  }
  #cssmenu ul ul li:hover > a {
    background: none;
    color: #8c9195;
  }
  #cssmenu ul ul ul a {
    padding: 8px 50px;
  }
  #cssmenu ul ul ul ul a {
    padding: 8px 65px;
  }
  #cssmenu ul ul ul ul ul a {
    padding: 8px 80px;
  }
  #cssmenu ul ul ul ul ul ul a {
    padding: 8px 95px;
  }
  #cssmenu > ul > #menu-button {
    display: block;
    cursor: pointer;
  }
  #cssmenu #menu-button > a {
    padding: 14px 20px;
  }
  #cssmenu ul.open li,
  #cssmenu > ul.open > li {
    display: block;
  }
  #cssmenu > ul.open > li#menu-button > a {
    color: #fff;
    border-bottom: 1px solid rgba(150, 150, 150, 0.1);
  }
  #cssmenu #menu-button::after {
    display: block;
    content: '';
    position: absolute;
    height: 3px;
    width: 22px;
    border-top: 2px solid #7a8189;
    border-bottom: 2px solid #7a8189;
    right: 20px;
    top: 15px;
  }
  #cssmenu #menu-button::before {
    display: block;
    content: '';
    position: absolute;
    height: 3px;
    width: 22px;
    border-top: 2px solid #7a8189;
    right: 20px;
    top: 25px;
  }
  #cssmenu ul.open #menu-button::after,
  #cssmenu ul.open #menu-button::before {
    border-color: #fff;
  }
}

3 个答案:

答案 0 :(得分:1)

您的媒体查询指向800px的最大宽度,使主菜单的无序列表以display: none消失。

基本上,媒体查询使浏览器在菜单的列表项上加载新的CSS display值。通过使元素display等于none,您告诉浏览器停止显示它,从而使该元素消失。

@media all and (max-width: 800px), only screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min--moz-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (-o-min-device-pixel-ratio: 2/1) and (max-width: 1024px), only screen and (min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min-resolution: 192dpi) and (max-width: 1024px), only screen and (min-resolution: 2dppx) and (max-width: 1024px) {

#cssmenu li, #cssmenu > ul > li{
   display: none
}

通过删除此行,您将获得沿网站的全宽延伸的水平菜单,我认为这是您正在寻找的,不是吗?


如果您想了解有关媒体查询及其工作原理的更多信息,可以在这篇关于这一主题的优秀文章中了解相关信息 - https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

答案 1 :(得分:0)

navbar.css中的第198行。当屏幕小于800px

时,您正在隐藏li
#cssmenu li, #cssmenu > ul > li {
    display: none;
}

答案 2 :(得分:0)

navbar.css

中的

#cssmenu li, #cssmenu > ul > li {
    display: none;
}