让我的下拉导航显示在其他div的前面

时间:2016-01-10 22:52:07

标签: html css

我使用HTML和CSS编写了一个Dropdown菜单,但我遇到了麻烦。我试图让我的下拉菜单显示在其他div的前面,但我似乎无法让它工作。

目前显示方式的屏幕截图:

enter image description here

代码:

.container {
  width: 1000px;
  margin: 0 auto;
  overflow: auto;
}

.header {
  background: #333;
  width: 100%;
  height: 80px;
}
.header .logo {
  background: url('../img/logo.png');
  width: 137px;
  height: 30px;
  float: left;
  display: block;
  margin: 25px 0 0 0;
}
.header .navigation {
  float: right;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  margin: 30px 0 0 0;
  list-style: none;
  list-style-image: none;
  text-transform: uppercase;
}
.header .navigation li {
  float: left;
  margin: 0 25px 0 0;
}
.header .navigation li a {
  color: #fff;
  text-decoration: none;
}
.header .navigation li a:hover, .header .navigation li a.current{
  color: #2abb9b;
}
.drop {
  float:left;
  list-style:none
}
li.drop {
  position:relative
}
.drop a:focus {
  border:0;
  outline:0
}
.drop>a {
  color:#FFF;
  font-weight:500;
  font-size:15px;
  text-decoration:none;
  margin:0 15px 15px 15px;
  display:block;
  -webkit-transition:all 100ms ease-out;
  -moz-transition:all 100ms ease-out;
  -o-transition:all 100ms ease-out;
  transition:all 100ms ease-out
}
.drop>a:hover {
  color:#199acb
}
.dropOut .triangle {
  width:0;
  height:0;
  position:absolute;
  border-left:8px solid transparent;
  border-right:8px solid transparent;
  border-bottom:8px solid white;
  top:-8px;
  left:50%;
  margin-left:-8px
}
.dropdownContain {
  width:160px;
  position:absolute;
  z-index:2;
  left:50%;
  margin-left:-80px;
  top:-400px
}
.dropOut {
  width:160px;
  background:white;
  float:left;
  position:relative;
  margin-top:0;
  opacity:0;
  -webkit-box-shadow:0 4px 10px rgba(0,0,0,0.25);
  -moz-box-shadow:0 4px 10px rgba(0,0,0,0.25);
  box-shadow:0 4px 10px rgba(0,0,0,0.25);
  -webkit-border-radius:3px;
  -moz-border-radius:3px;border-radius:3px;
  -webkit-background-clip:padding-box;
  -moz-background-clip:padding;
  background-clip:padding-box
}
.dropOut ul {
  float:left;
  padding:0;
  margin:0
}
.dropOut a {
  color:#444;
  font-weight:500;
  font-size:13px;
  text-decoration:none;
  padding:10px;
  display:block;
  -webkit-transition:all 50ms ease-out;
  -moz-transition:all 50ms ease-out;
  -o-transition:all 50ms ease-out;
  transition:all 50ms ease-out;
  width:140px
}
.dropOut a:hover {
  background-color:#f7f7f7;
  color:#199acb
}
.dropOut li:first-child a:hover {
  -webkit-border-radius:4px 4px 0 0;
  border-radius:4px 4px 0 0;
  -webkit-background-clip:padding-box;
  -moz-background-clip:padding;
  background-clip:padding-box
}
.dropOut li:last-child a:hover {
  -webkit-border-radius:0 0 4px 4px;
  border-radius:0 0 4px 4px;
  -webkit-background-clip:padding-box;
  -moz-background-clip:padding;
  background-clip:padding-box
}
li:hover .dropdownContain {
  top:20px
}
li:hover .dropOut {
  opacity:1;
  margin-top:12px
}
<div class="header">
  <div class="container">
    <a href="index.html" class="logo"></a>
    <ul class="navigation">
      <li><a href="" class="current">Home</a></li>
      <li><a href="">About</a></li>
      <li class="drop">
        <a href="/home" class="">vBulletin</a>
        <div class="dropdownContain">
          <div class="dropOut">
            <div class="triangle"></div>
            <ul>
              <li><a href="">Custom Themes</a></li>
              <li><a href="">Premade Themes</a></li>
            </ul>
          </div>
        </div>
      <li><a href="">Support</a></li>
    </ul>
  </div>
</div>

我非常感谢任何帮助,因为我花了几个小时试图找出解决问题的方法。

2 个答案:

答案 0 :(得分:2)

问题在于

.container {
  overflow: auto;
}

要显示折叠菜单,溢出应该是可见的。将auto更改为visible似乎可以解决您的问题,但您也可以将其删除,因为visible是默认设置。

.container {
  width: 1000px;
  margin: 0 auto;
}

.header {
  background: #333;
  width: 100%;
  height: 80px;
}
.header .logo {
  background: url('../img/logo.png');
  width: 137px;
  height: 30px;
  float: left;
  display: block;
  margin: 25px 0 0 0;
}
.header .navigation {
  float: right;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  margin: 30px 0 0 0;
  list-style: none;
  list-style-image: none;
  text-transform: uppercase;
}
.header .navigation li {
  float: left;
  margin: 0 25px 0 0;
}
.header .navigation li a {
  color: #fff;
  text-decoration: none;
}
.header .navigation li a:hover, .header .navigation li a.current{
  color: #2abb9b;
}
.drop {
  float:left;
  list-style:none
}
li.drop {
  position:relative
}
.drop a:focus {
  border:0;
  outline:0
}
.drop>a {
  color:#FFF;
  font-weight:500;
  font-size:15px;
  text-decoration:none;
  margin:0 15px 15px 15px;
  display:block;
  -webkit-transition:all 100ms ease-out;
  -moz-transition:all 100ms ease-out;
  -o-transition:all 100ms ease-out;
  transition:all 100ms ease-out
}
.drop>a:hover {
  color:#199acb
}
.dropOut .triangle {
  width:0;
  height:0;
  position:absolute;
  border-left:8px solid transparent;
  border-right:8px solid transparent;
  border-bottom:8px solid white;
  top:-8px;
  left:50%;
  margin-left:-8px
}
.dropdownContain {
  width:160px;
  position:absolute;
  z-index:2;
  left:50%;
  margin-left:-80px;
  top:-400px
}
.dropOut {
  width:160px;
  background:white;
  float:left;
  position:relative;
  margin-top:0;
  opacity:0;
  -webkit-box-shadow:0 4px 10px rgba(0,0,0,0.25);
  -moz-box-shadow:0 4px 10px rgba(0,0,0,0.25);
  box-shadow:0 4px 10px rgba(0,0,0,0.25);
  -webkit-border-radius:3px;
  -moz-border-radius:3px;border-radius:3px;
  -webkit-background-clip:padding-box;
  -moz-background-clip:padding;
  background-clip:padding-box
}
.dropOut ul {
  float:left;
  padding:0;
  margin:0
}
.dropOut a {
  color:#444;
  font-weight:500;
  font-size:13px;
  text-decoration:none;
  padding:10px;
  display:block;
  -webkit-transition:all 50ms ease-out;
  -moz-transition:all 50ms ease-out;
  -o-transition:all 50ms ease-out;
  transition:all 50ms ease-out;
  width:140px
}
.dropOut a:hover {
  background-color:#f7f7f7;
  color:#199acb
}
.dropOut li:first-child a:hover {
  -webkit-border-radius:4px 4px 0 0;
  border-radius:4px 4px 0 0;
  -webkit-background-clip:padding-box;
  -moz-background-clip:padding;
  background-clip:padding-box
}
.dropOut li:last-child a:hover {
  -webkit-border-radius:0 0 4px 4px;
  border-radius:0 0 4px 4px;
  -webkit-background-clip:padding-box;
  -moz-background-clip:padding;
  background-clip:padding-box
}
li:hover .dropdownContain {
  top:20px
}
li:hover .dropOut {
  opacity:1;
  margin-top:12px
}
<div class="header">
  <div class="container">
    <a href="index.html" class="logo"></a>
    <ul class="navigation">
      <li><a href="" class="current">Home</a></li>
      <li><a href="">About</a></li>
      <li class="drop">
        <a href="/home" class="">vBulletin</a>
        <div class="dropdownContain">
          <div class="dropOut">
            <div class="triangle"></div>
            <ul>
              <li><a href="">Custom Themes</a></li>
              <li><a href="">Premade Themes</a></li>
            </ul>
          </div>
        </div>
      <li><a href="">Support</a></li>
    </ul>
  </div>
</div>

答案 1 :(得分:0)

另一个只是删除

.container { 
  overflow: auto;
}

然后放手吧?