dropdownt未在导航栏中显示

时间:2017-09-28 11:12:55

标签: html css

这是我的全部代码。我只是徘徊这是错误的,我的下拉列表没有在导航栏中显示。我只是徘徊,如果somone可以帮助我在这里解决这个问题,我仍然是新的html和CSS。

<html>
<head>
<title> Curriculum </title>
<style>

body {
  margin: 0;
  padding: 0;
  background: #333;
  background-attachment: fixed;
  background-size: cover;
}

#video-background {
  position: fixed;
  right: 0; 
  bottom: 0;
  min-width: 100%; 
  min-height: 100%;
  width: auto; 
  height: auto;
  z-index: -100;
}

.header{
    width: 1100px;
    height: 350px;
    margin: auto;
    }
.nav{
    width 1100px;
    margin: auto;
    overfow: auto;
    }
ul{
    list-style-type: none;
        margin: 0;
     padding: 0;
     overflow: hidden;
     background-color: Maroon;
    opacity: .8;
    }
li{
    float: left;
    }
li:last-child {
    border-right: none;
    }
a:link{
    color: cyan;
    widht: 125px;
    text-decoration: none;
    display: block;
    text-alignment: center;
    padding: 15px;
    text-transfrom: uppercase;
    font-size: 18px;
    font-family: verdana; 
    }
li a {
    display: block;
    color: yellow;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover:not(.active) {
    background-color: cyan;
}

.active {
    background-color: White;
}


.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: white;
    width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.desc {
    padding: 15px;
    text-align: center;
}
.dropbtn {
    background-color: Maroon;
    color: yellow;
    padding: 16px;
    font-size: 18px;
    border: none;
    cursor: pointer;
}
.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropbtn {
    background-color: cyan;
}
</style>
</head>
<body>


<video autoplay loop id="video-background" muted plays-inline>
  <source src="A.mp4" type="video/mp4">
</video>

<div class  = "header">
<img src = "Header.jpg" width = "1100px" height = "150px">
<div class = "nav">
<ul>
    <li><a href = "Home.html #Home"> Home </a></li>
    <li><a href = "Mission_Vision.html #Mission & Vision"> Mission & Vision </a></li>
    <li><a href = "#"> Org.Chart </a></li>
    <li><div class="dropdown">
  <button class="dropbtn">Curriculum</button>
  <div class="dropdown-content">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
  </div>
</div>
</li>
    <li style="float:right"><a href="Contact.html#about">Contact Us</a></li>
</ul>
</div>
</body>
</html>

我如何解决这个问题帮助我某人提前感谢能够帮助我的人。我已经在某些网站上复制了一些代码,但仍无法正常工作。

1 个答案:

答案 0 :(得分:1)

您已将position: relative添加到.dropdown  .dropdown-content.dropdown的孩子,被absolute

因此,它保持在它的父母的边界内,因此不可见。

删除position: relative然后就可以了。

body {
  margin: 0;
  padding: 0;
  background: #333;
  background-attachment: fixed;
  background-size: cover;
}

#video-background {
  position: fixed;
  right: 0; 
  bottom: 0;
  min-width: 100%; 
  min-height: 100%;
  width: auto; 
  height: auto;
  z-index: -100;
}

.header{
    width: 1100px;
    height: 350px;
    margin: auto;
    }
.nav{
    width 1100px;
    margin: auto;
    overfow: auto;
    }
ul{
    list-style-type: none;
        margin: 0;
     padding: 0;
     overflow: hidden;
     background-color: Maroon;
    opacity: .8;
    }
li{
    float: left;
    }
li:last-child {
    border-right: none;
    }
a:link{
    color: cyan;
    widht: 125px;
    text-decoration: none;
    display: block;
    text-alignment: center;
    padding: 15px;
    text-transfrom: uppercase;
    font-size: 18px;
    font-family: verdana; 
    }
li a {
    display: block;
    color: yellow;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover:not(.active) {
    background-color: cyan;
}

.active {
    background-color: White;
}


.dropdown {
    /*position: relative; < remove this line */
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: white;
    width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.desc {
    padding: 15px;
    text-align: center;
}
.dropbtn {
    background-color: Maroon;
    color: yellow;
    padding: 16px;
    font-size: 18px;
    border: none;
    cursor: pointer;
}
.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropbtn {
    background-color: cyan;
}
<video autoplay loop id="video-background" muted plays-inline>
  <source src="A.mp4" type="video/mp4">
</video>

<div class  = "header">
<img src = "Header.jpg" width = "1100px" height = "150px">
<div class = "nav">
<ul>
    <li><a href = "Home.html #Home"> Home </a></li>
    <li><a href = "Mission_Vision.html #Mission & Vision"> Mission & Vision </a></li>
    <li><a href = "#"> Org.Chart </a></li>
    <li><div class="dropdown">
  <button class="dropbtn">Curriculum</button>
  <div class="dropdown-content">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
  </div>
</div>
</li>
    <li style="float:right"><a href="Contact.html#about">Contact Us</a></li>
</ul>
</div>