包装器中的导航下拉菜单未显示第二级

时间:2014-12-05 15:01:48

标签: css drop-down-menu overflow navbar

我有问题。我在容器中有一个导航菜单,但当我进入导航菜单查看第二级时,包装器会创建一个滚动条而我不喜欢它。它应该显示容器外的菜单。我知道问题在于某个地方如何设置溢出,但我到处搜索,我找不到解决问题的方法。也许有人可以帮助我。

所以基本上这是光标不在上面的菜单: http://www.upload.ee/image/4395605/beforemain.png

但是当我转到“关于”部分时,它应该显示容器外的下拉菜单。不幸的是,现在情况并非如此。它现在看起来的链接: http://www.upload.ee/image/4395606/aftermain.png

这是我的HTML代码:          

<head>
<title></title>
<LINK REL="stylesheet" TYPE="text/css" HREF="style.css">
</head>

<body>
<!-- header -->
<div class="header">
<!-- logo -->
<img id="logo" class="bottom" src="http://29.media.tumblr.com/tumblr_kzkw4r9qKj1qal1fmo1_400.jpg"/>
<!-- navigation menu -->
<nav>
    <ul>
        <li><a href="UT.html">Home</a></li>
        <li><a href="#">About <span class="caret"></span></a>
            <div>
                <ul>
                    <li><a href="Team.html">Team</a></li>
                    <li><a href="Coaches.html">Coaches</a></li>
                </ul>
            </div>
        </li>
        <li><a href="Sponsors.html">Sponsors</a></li>
        <li><a href="Contact.html">Contact</a></li>
    </ul>
</nav>
</div>

<!-- Maintained by -->
<div class="hr">
<hr />
<address>&copy 
<a href="mailto:">Anonymous</a> Last changed 04/12/2014</address>
</div>

</body>

</html>

我还要包含我的CSS代码:

html {
    background-color: #FFFFFD;
}

body {
    width: 960px;
    margin: 10px auto 5px auto;
    background-color: white;
    padding: 20px;
    box-shadow: 0px 0px 20px #888888;
    font-family: 'Vollkorn', Georgia, Times, serif;
    font-size: 16px;
    line-height: 25px;
}

h1 {
    font-family:verdana; 
    color:#8B5742;
}

h2 {
    font-family:verdana; 
    color:#CD8162;
}

h3 {
    font-family:verdana; 
    color:#FFA07A;
}

img {
    margin: 5px;
}

div {
    max-width:940px;
}

div.header {
    margin: 8px 8px 8px 8px;
    width: 100%;
    height: auto;
    background-color: #fff;
    display: block;
    position: relative;
    border: 1px solid #dedede;
    border-radius: 4px;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
    overflow: auto; 
}

#logo {
    width: 200px;
    height: 200px;
    float: left;
}

img.bottom {
    vertical-align: text-bottom;
}

nav {
    background-color: #fff;
    color: #888;
    position: absolute;
    margin: 8px 22px 8px 22px;
    right: 0px;
    bottom: 2px;
}

nav ul {
    margin: 0;
    padding: 0;
}

nav ul li {
    display: inline-block;
    list-style-type: none;
}

nav > ul > li > a > .caret {
    border-top: 4px solid #aaa;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
    content: "";
    display: inline-block;
    height: 0;
    width: 0;
    vertical-align: middle;
}

nav > ul > li > a {
    color: #aaa;
    display: block;
    line-height: 56px;
    padding: 0 24px;
    text-decoration: none;
}

nav > ul > li:hover {
    background-color: rgb( 40, 44, 47 );
}

nav > ul > li:hover > a {
    color: rgb( 255, 255, 255 );
}

nav > ul > li:hover > a > .caret {
    border-top-color: rgb( 255, 255, 255 );
}

nav > ul > li > div {
    background-color: rgb( 40, 44, 47 );
    border-top: 0;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
    display: none;
    margin: 0;
    opacity: 0;
    position: absolute;
    width: 165px;
    visibility: hidden;
}

nav > ul > li:hover > div {
    display: block;
    opacity: 1;
    visibility: visible;
}

nav > ul > li > div ul > li {
    display: block;
}

nav > ul > li > div ul > li > a {
    color: #fff;
    display: block;
    padding: 12px 24px;
    text-decoration: none;
}

nav > ul > li > div ul > li:hover > a {
    background-color: rgba( 255, 255, 255, 0.1);
}

div.hr {
    text-align: center;
    font-size: 12px;
    padding: 10px 10px 10px 10px;
}

div.hr hr{
    border: 0;
    color: #000000;
    background-color: #000000;
    height: 1px;
    width: 70%;
    margin-top: 15px;
    margin-bottom: 15px;
}

1 个答案:

答案 0 :(得分:0)

您需要的是清除 header内的浮动元素,您可以删除溢出:auto也是如此。试试这个:

div.header {
  margin: 8px 8px 8px 8px;
  width: 100%;
  background-color: #fff;
  display: block;
  position: relative;
  border: 1px solid #dedede;
  border-radius: 4px;
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
}
div.header:after {
  content:" ";
  display:block;
  clear:both;
}

检查下面的代码段以查看工作示例。

html {
  background-color: #FFFFFD;
}
body {
  width: 960px;
  margin: 10px auto 5px auto;
  background-color: white;
  padding: 20px;
  box-shadow: 0px 0px 20px #888888;
  font-family: 'Vollkorn', Georgia, Times, serif;
  font-size: 16px;
  line-height: 25px;
}
h1 {
  font-family: verdana;
  color: #8B5742;
}
h2 {
  font-family: verdana;
  color: #CD8162;
}
h3 {
  font-family: verdana;
  color: #FFA07A;
}
img {
  margin: 5px;
}
div {
  max-width: 940px;
}
div.header {
  margin: 8px 8px 8px 8px;
  width: 100%;
  background-color: #fff;
  display: block;
  position: relative;
  border: 1px solid #dedede;
  border-radius: 4px;
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
}
div.header:after {
  content:" ";
  display:block;
  clear:both;
}
#logo {
  width: 200px;
  height: 200px;
  float: left;
}
img.bottom {
  vertical-align: text-bottom;
}
nav {
  background-color: #fff;
  color: #888;
  position: absolute;
  margin: 8px 22px 8px 22px;
  right: 0px;
  bottom: 2px;
}
nav ul {
  margin: 0;
  padding: 0;
}
nav ul li {
  display: inline-block;
  list-style-type: none;
}
nav > ul > li > a > .caret {
  border-top: 4px solid #aaa;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  content: "";
  display: inline-block;
  height: 0;
  width: 0;
  vertical-align: middle;
}
nav > ul > li > a {
  color: #aaa;
  display: block;
  line-height: 56px;
  padding: 0 24px;
  text-decoration: none;
}
nav > ul > li:hover {
  background-color: rgb(40, 44, 47);
}
nav > ul > li:hover > a {
  color: rgb(255, 255, 255);
}
nav > ul > li:hover > a > .caret {
  border-top-color: rgb(255, 255, 255);
}
nav > ul > li > div {
  background-color: rgb(40, 44, 47);
  border-top: 0;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
  display: none;
  margin: 0;
  opacity: 0;
  position: absolute;
  width: 165px;
  visibility: hidden;
}
nav > ul > li:hover > div {
  display: block;
  opacity: 1;
  visibility: visible;
}
nav > ul > li > div ul > li {
  display: block;
}
nav > ul > li > div ul > li > a {
  color: #fff;
  display: block;
  padding: 12px 24px;
  text-decoration: none;
}
nav > ul > li > div ul > li:hover > a {
  background-color: rgba(255, 255, 255, 0.1);
}
div.hr {
  text-align: center;
  font-size: 12px;
  padding: 10px 10px 10px 10px;
}
div.hr hr {
  border: 0;
  color: #000000;
  background-color: #000000;
  height: 1px;
  width: 70%;
  margin-top: 15px;
  margin-bottom: 15px;
}
<div class="header">
  <img id="logo" class="bottom" src="http://29.media.tumblr.com/tumblr_kzkw4r9qKj1qal1fmo1_400.jpg" />
  <nav>
    <ul>
      <li><a href="UT.html">Home</a>
      </li>
      <li><a href="#">About <span class="caret"></span></a>
        <div>
          <ul>
            <li><a href="Team.html">Team</a>
            </li>
            <li><a href="Coaches.html">Coaches</a>
            </li>
          </ul>
        </div>
      </li>
      <li><a href="Sponsors.html">Sponsors</a>
      </li>
      <li><a href="Contact.html">Contact</a>
      </li>
    </ul>
  </nav>
</div>
<div class="hr">
  <hr />
  <address>&copy 
<a href="mailto:">Anonymous</a> Last changed 04/12/2014</address>
</div>