html - 如何在内容上方制作下拉菜单

标签 html css

我已经成功创建了一个响应式导航栏,但也制作了下拉菜单,但是当有 A div 时,下拉菜单位于内容下方任何人都知道我能做什么,谢谢。

HTML

<!DOCTYPE html>
<html>
<head>
<title>Mac gallery</title>
    <link rel="stylesheet" type="text/css" href="css/nav.css">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<link rel="stylesheet" type="text/css" href="css/gallerystyles.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">

<script src="js/nav.js"></script>
<script src="js/javascript.js"></script>
<script src="js/footer.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script src="js/galleria/galleria-1.5.7.min.js"></script>



<style>
.galleria{ max-width: 700px; height: 400px; background: #000 }
</style>

<script>
(function() { 
    Galleria.loadTheme('js/galleria/themes/classic/galleria.classic.min.js');
Galleria.run('.galleria');
}());
</script>



</head>
<body onload="time()">

<nav>

    <ul class="topnav" id="myTopnav">

    <a href="index.html"><li>Home</li></a>
    <div class="dropdown">
    <li class="dropbtn" onclick="myFunction1()">Gallerys</li>
      <div class="dropdown-content" id="myDropdown">
       <a href="iphonegallery.html"><li>Iphone Gallery</li></a>
       <a href="macgallery.html"><li>Mac Gallery</li></a>
       <a href="ipodgallery.html"><li>Ipad Gallery</li></a>
     </div>
    </div> 
    <a href="contectus.html"><li>Contact US</li></a>

    <a href="javascript:void(0);" class="icon" onclick="myFunction()"><li>&#9776;</li></a>
    </ul>
</nav>

<div class="galleria">
<img src="img/macgallery/Imac.jpg">
<img src="img/macgallery/macbook.png">
<img src="img/macgallery/macbookpro.jpg">
<img src="img/macgallery/macmini.jpg">
</div>











<footer>

<p>Develop and maintain by Alastair Micallef (<span id="date"></span>)</p>

<ul class="footernav">

    <a href=""><li>Home</li></a>
    <a href=""><li>Gallery</li></a>
    <a href=""><li>Iphone gallery</li></a>
    <a href=""><li>Mac gallery</li></a>
    <a href=""><li>Ipad gallery</li></a>
    <a href=""><li>Iphone History</li></a>
    <a href=""><li>Mac Hostory</li></a>
    <a href=""><li>Ipod Histry</li></a>

</ul>


</footer>

</body>
</html>

CSS

/* Add a black background color to the top navigation */
    .topnav {
        background-color: #333;
        overflow: hidden;
    }

    /* Style the links inside the navigation bar */
    .topnav a {
        float: left;
        display: block;
        color: #f2f2f2;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
        font-size: 17px;
    }

    /* Change the color of links on hover */
    .topnav a:hover {
        background-color: #ddd;
        color: black;
    }

    /* Hide the link that should open and close the topnav on small screens */
    .topnav .icon {
        display: none;
    }

    .dropdown {
        float: left;
        overflow: hidden;
        position: absolute;
    }

    .dropdown .dropbtn {
        cursor: pointer;
        font-size: 16px;    
        border: none;
        outline: none;
        color: white;
        padding: 14px 16px;
        background-color: inherit;
        display: none;
    }

    .container a:hover, .dropdown:hover .dropbtn {
        background-color: red;
    }

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

    .dropdown-content a {
        float: none;
        color: black;
        padding: 12px 16px;
        text-decoration: none;
        display: block;
        text-align: left;
    }

    .dropdown-content a:hover {
        background-color: #ddd;
    }

    .show {
        display: none;
    }





    /* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
    @media screen and (max-width: 600px) {
      .topnav a:not(:first-child) {display: none;}
      .topnav a.icon {
        float: right;
        display: block;
      }
    }

    /* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
    @media screen and (max-width: 600px) {
      .topnav.responsive {position: relative;}
      .topnav.responsive a.icon {
        position: absolute;
        right: 0;
        top: 0;
      }
      .topnav.responsive a {
        float: none;
        display: block;
        text-align: left;
      }
    }

    li{
        list-style: none;
    }

最佳答案

将您所有的代码放到网站上。提供的代码还不够

关于html - 如何在内容上方制作下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44191895/

相关文章:

jquery - 在文档加载事件的类上添加图像

html - 为什么我的 svg 没有在 div 容器中居中?

javascript - 如何保留一些对象并移除其他对象

html - 为什么文本链接和图标链接不是垂直居中的?

html - 设置固定标题可滚动内容仅 css html 表

CSS:如何阻止固定导航栏重叠滚动条?

javascript - 点击跟踪器的颜色变化

css - 通过样式表为 WordPress 主题中的每个配色方案应用不同的 Logo

HTML页面中的JavaScript代码运行顺序

visual-studio-2010 - Visual Studio 2010 中的 HTML5 和 CSS3 智能感知