下拉菜单没有出现

时间:2019-11-06 00:08:13

标签: html css dropdown

试图显示此下拉菜单,但我不确定出什么问题。

这是我的代码笔:https://codepen.io/JBeezy3/pen/PooQwZr

<body>
          <div class="container">
              <!-- will add in later -->
            <div class="header" <img>
            </div>
            <div class="menu">
              <nav>
                <ul>
                  <li><a style="text-decoration:none" href="Home">Home</a></li>
                  <li><a style="text-decoration:none" href="Home">About</a></li>
                  <li><a style="text-decoration:none" href="works.html">Works</a>
                    <ul class="sub-menu">
                      <li> Digital </li>
                      <li> Physical </li>
                      <li> Animation </li>
                    </ul>
                  <li><a style="text-decoration:none" href="Home">Contact</a></li>
                </ul>
              </nav>
            </div>

2 个答案:

答案 0 :(得分:0)

首先,子菜单的文本显示为黑色(这是默认颜色),这就是为什么您在黑色背景上看不到它的原因。将color: #fff添加到ul.sub-menu li以使其可见。然后,您可以修复其余部分。

答案 1 :(得分:0)

替换此CSS

*{
    margin: 0;
    padding: 0;
    -webkit-box-sizing: border-box;
  }
  
  body {
    font-family: verdana; 
    font-size: 14px;
    font-weight: normal;
    height: 100%;
    background: url(../img) no-repeat;
    background-size: cover;
    background-attachment: fixed;
    background-color: black;
  }
  .header{
    padding: 15px 35px; 
    display: inline-block;
    width: 100%;
  }
  a{
    color: white;
    text-decoration: none;
  }
  .menu {
    float: right;
  }
  .menu ul li {
    display: inline-block;
    float: left;
    line-height: 24px;
    margin: 15px;
  }
  .menu ul li a{
    text-decoration: none;
    color: #ffffff;
    font-size: 24px;
    padding: 5px 10px;
  }
  .menu ul li a:hover{
    color: red;
  }
  
  .name{
    width: 350px; 
    margin-top: 300px;
    margin-right: 500px;
  }
  .name h5{
    color: red;
    font-size: 24.5px;
    text-align: left;
  }
  .name h1{
    color: white;
    font-size: 90px;
    line-height: 75px;
  }
  
  .sub-menu{
    position: absolute; 
    display: none;
    background-color: white;
  }
  .menu li:hover a + .sub-menu { display: block;}
  .sub-menu li{
    position: relative;
    display: block;
  }
  .column-left { 
      float: left; 
      width: 33.333%; 
    }
  .column-right { 
      float: right; 
      width: 33.333%; 
      padding-left: 0px;
    }
  .column-center { 
      display: inline-block; 
      width: 33.333%; 
      padding-top: 80px;
  }

  .row {
      color: white;
      font-size: 24px;
      margin: 150px;
      text-align: center;
  }

.preview {
    width: 90%;
}
.preview2 {
    width: 75%;
}
.preview3 {
    width: 70%
}
.hero{
    max-width: 500px;
    margin-left: 500px;
    padding-bottom: 1000px;
}
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>John Blair Graphic Designer</title>
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <div class="container">
        <!-- will add in later -->
        <div class="header">
        <div class="menu">
            <nav>
                <ul>
                    <li><a style="text-decoration:none" href="index.html">Home</a></li>
                    <li><a style="text-decoration:none" href="Home">About</a></li>
                    <li><a style="text-decoration:none" href="works.html">Works</a>
                        <ul class="sub-menu">
                            <li> Digital </li>
                            <li> Physical </li>
                            <li> Animation </li>
                        </ul>
                    </li>
                    <li><a style="text-decoration:none" href="Home">Contact</a></li>
                </ul>
            </nav>
        </div>
        <div class="name">
            <h5>Graphic Designer</h5>
            <h1> John Blair </h1>
        </div>
        <img class="hero" src="images/hero.jpg">
<footer>
    <!-- nav menu when working-->
</footer>