如何使下拉导航栏全宽

时间:2015-06-02 17:50:32

标签: html css navbar

我有一个带有以下HTML的导航栏:

<nav id="menu-bar">
<ul>
  <li><a href='http://sunilpatro1985.blogspot.in/' >Home</a></li>
  <li><a href='http://sunilpatro1985.blogspot.in/search/label/SeleniumTesting'>Selenium</a>
    <ul>
      <li><a href='http://sunilpatro1985.blogspot.in/2015/04/selenium-testng.html'>TestNG</a></li>
      <li><a href='http://sunilpatro1985.blogspot.com/2015/03/selenium-result-report-testng-ant.html'>ANT Reporting</a></li>
    </ul>
  </li>
  <li><a href='http://sunilpatro1985.blogspot.in/search/label/SoftwareTesting'>TestingConcepts</a></li>
  <li><a href='http://sunilpatro1985.blogspot.in/search/label/BasicJava' >JavaBasics</a></li>
  <li><a href='http://sunilpatro1985.blogspot.in/search/label/WindowsOS' >Windows</a></li>
  <li><a href='http://sunilpatro1985.blogspot.in/p/demo.html' >Demo</a></li>
</ul></nav>

和我使用的CSS:

#menu-bar {position: fixed; top: 0px; left: 0px; z-index: 999;height:0px;}
#menu-bar,#menu-bar a {
  text-align: center;
  margin: 0px 0px;
border:none;
}
#menu-bar ul ul {
  display: none;
}
#menu-bar ul li:hover > ul {
  display: block;
}
#menu-bar ul {
  background: #efefef; 
  background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);  
  background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%); 
  background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%); 
  box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
  padding: 0 20px;
  border-radius: 7px;  
  list-style: none;
  position: relative;
  display: inline-table;
  overflow:visible;
}
#menu-bar ul:after {
  content: ""; clear: both; display: block;
}
#menu-bar ul li {
  float: left;
}
#menu-bar ul li:hover {
  background: #4b545f;
  background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
  background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
  background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
#menu-bar ul li:hover a {
  color: #fff;
}
#menu-bar ul li a {
  display: block; padding: 15px 30px;
  color: #757575; text-decoration: none;
}
#menu-bar ul ul {
  background: #5f6975; border-radius: 0px; padding: 0;
  position: absolute; top: 100%;
}
#menu-bar ul ul li {
  float: none; 
  border-top: 1px solid #6b727c;
  border-bottom: 1px solid #575f6a;
  position: relative;
}
#menu-bar ul ul li a {
  padding: 15px 30px;
  color: #fff;
}
#menu-bar ul ul li a:hover {
  background: #4b545f;
}
#menu-bar ul ul ul {
  position: absolute; left: 100%; top:0;
}

以上菜单栏仅覆盖我桌面屏幕的80%。我怎样才能使它全宽?我尝试了其他Stack Overflow答案中提到的一些选项,但没有任何帮助。请帮我在屏幕上全屏显示菜单栏。

3 个答案:

答案 0 :(得分:0)

只需将right: 0添加到#menu-bar

#menu-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0; /* <-- here */
    z-index: 999;
    height: 0; /* why is the height "0"? */
}

答案 1 :(得分:0)

看起来您实际上并未将导航元素设置为CSS中宽度的100%。尝试添加:

#menu-bar { width: 95%;}
#menu-bar > ul {width: 100% }

在jsFiddle中有效,但您可能需要调整菜单栏的百分比(第一行)。

答案 2 :(得分:0)

试试这段代码:

#menu-bar{width:100%}    
#menu-bar ul{width:100%}