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 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀