You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bootstrap下拉菜单无法显示/被背景遮挡问题求助

导航栏下拉菜单无法显示的修复方案

你的问题出在两处overflow: hidden的设置上,它们会把Bootstrap下拉菜单的弹出内容裁剪隐藏:

问题根源

  1. <ul>元素的overflow: hidden:Bootstrap下拉菜单默认是绝对定位,会超出父容器<ul>的范围,而overflow: hidden会把超出部分完全隐藏。
  2. body元素的overflow: hidden:这个设置会限制页面的滚动区域,下拉菜单弹出后如果超出当前视口,会被直接截断。

修复步骤

1. 移除<ul>的overflow: hidden,替换为清除浮动的方案

因为原来的<li>用了float: left,需要清除浮动来避免父容器高度塌陷,推荐用CSS伪元素实现:

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  /* 移除 overflow: hidden */
  background-color: rgb(87, 41, 41);
}

/* 添加清除浮动的伪元素 */
ul::after {
  content: "";
  display: table;
  clear: both;
}

2. 移除body的overflow: hidden

如果需要背景图全屏显示,保留background-size: cover即可,移除overflow: hidden后下拉菜单就能正常弹出:

body {
  background: url(../img/main_learn.jpg) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  /* 移除 overflow: hidden */
}

修改后的完整代码

CSS 代码

.info {
  margin-top: 15%;
  display: table;
  height: 100%;
  width: 100%;
}

#navbar {
  background: red;
  position: fixed;
  top: 0px;
  width: 100%;
}

.content {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  color: #fff;
  font-size: 12px;
}

h1 {
  color: rgb(255, 255, 255);
  border: 3px solid #fff;
  text-align: center;
  background: rgba(0, 0, 0, 0.1);
  font-size: 40px;
  font-weight: normal;
  padding: 30px;
  margin: 15px;
  display: inline-block;
  background: rgba(0, 0, 0, 0.4);
}

/* Menu */
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  background-color: rgb(87, 41, 41);
}

ul::after {
  content: "";
  display: table;
  clear: both;
}

li {
  float: left;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 20px 25px;
  text-decoration: none;
}

li a:hover {
  background-color: #111;
}

.active {
  background-color: #04AA6D;
}

.conc {
  float: right;
}

html,
body {
  height: 100%;
}

body {
  background: url(../img/main_learn.jpg) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

input[type=range] {
  margin: 10px;
  width: 50px;
}

HTML 代码

<div id="navbar">
  <ul>
    <li><a href="index.php?idp=glowna">Strona główna</a></li>
    <li><a href="index.php?idp=aktualnosci">Aktualności</a></li>
    <li><a href="index.php?idp=instrumenty">Instrumenty</a></li>
    <li><a href="index.php?idp=musicale">Musicale</a></li>
    <li><a href="index.php?idp=nauka">Nauka</a></li>
    <li><a href="index.php?idp=chart">Charty</a></li>
    <li><a href="index.php?idp=filmy">Filmy</a></li>
    <li><a href="index.php?idp=chaos">Chaos</a></li>
    <li class="conc">
      <div class="dropdown show">
        <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown link
        </a>

        <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </div>
      <!-- <a href="index.php?idp=kontakt"><b>Kontakt</b></a> -->
    </li>
  </ul>
</div>

内容的提问来源于stack exchange,提问作者Rolegur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 05:01:09