douzhao9608 2018-06-11 12:37
浏览 113
已采纳

导航栏下拉列表不会出现

In my website I have created a NavBar file and I include it, with php, in every other php file I want. Now my navbar file has a dropdown inside:

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

.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
  box-shadow: white;
  z-index: 1;
  cursor: pointer;
}

.dropdown-inbuttons {
  border: none;
  padding: 6px 12px;
  text-decoration: none;
  display: inline-block;
  cursor: pointer;
  background-color: white;
  color: black;
}

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

.dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  background-color: white;
  min-width: 160px;
  box-shadow: white;
  z-index: 1;
  cursor: pointer;
}

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

.dropdown:hover .dropdown-content {
  display: block;
}
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">


<div class="w3-top">
  <div class="w3-bar w3-black w3-card" style="height: 58px">
    <!-- Give attension here -->
    //.....other code....//
    <div class="dropdown" style="margin-top: 6px;">
      <button class="dropbtn">
              <i class="fa fa-caret-down"></i>
            </button>
      <div class="dropdown-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="../../../../registration/_includes/logout-system.php">Log Out</a>
      </div>
    </div>
  </div>

</div>

When I put my mouse up to the dropbtn it shows me this: enter image description here

I know why this happen because the dropdown content is inside the navbar and in the code navbar height = 58px and doesn't fit. So How to make my dropdown visible front of the other html files?

I import the navbar in other php files with this way:

<html>
    <?php
    session_start();

    if(!isset($_SESSION['u_id'])){ 
    header("Location: ../../login.php");
    }
    include '../../_includes/server.php';
    $userid = $_SESSION['u_id'];
    $usersql = "SELECT * FROM `users` WHERE id='$userid'";
    $result = mysqli_query($conn, $usersql);
    if($row = mysqli_fetch_assoc($result))
    {
        $_SESSION['first_name'] = $row['first_name'];
        $_SESSION['last_name'] = $row['last_name'];
        include('../../../navBar/navBarConnected.php'); <!-- Here I include it-->
    }
    <head>...</head>
    <body>...</body>
</html>
</div>
  • 写回答

2条回答 默认 最新

  • dongmeixi5311 2018-06-11 12:55
    关注

    First approach: Override overflow:hidden of .w3-bar by overflow:visible.

    Second approach: Change position: relative of .dropdown class to position: static and wrap the <div class="dropdown">...</div> to another div and add position: relative to that.

    Both of them will work. Choose whatever suits you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 腾讯云如何建立同一个项目中物模型之间联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码