我使用Bootstrap 4构建一个具有通知下拉列表的站点,该站点当然是为了覆盖页面主体的内容。问题是,即使在下拉列表中使用z-index:10000,Packery网格项也会继续显示在菜单上。
我不能为我的生活弄清楚为什么会这样,并且z-index,position:absolute,position:relative的各种组合,以及我能想到的其他所有技巧都失败了。使用popover.js的弹出窗口确实在Packery上正确定位,有趣的是。
有关解决方案的任何建议吗?
由于Codepen链接需要代码,这里是下拉代码,尽管这对您没有多大帮助。
<li class="nav-item dropdown dropper">
<a class="nav-link text-light" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-bell">Notifications</i>
</a>
<ul class="dropdown-menu">
<li class="head text-light bg-dark">
<div class="row">
<div class="col-lg-12 col-sm-12 col-12">
<span>Notifications (3)</span>
<a href="" class="float-right">Mark all as read</a>
</div>
</li>
<li class="notification-box">
<div class="row">
<div class="col-lg-3 col-sm-3 col-3 text-center">
<img src="/demo/man-profile.jpg" class="w-50 rounded-circle">
</div>
<div class="col-lg-8 col-sm-8 col-8">
<strong class="text-info">David John</strong>
<div>
Lorem ipsum dolor sit amet, consectetur
</div>
<small class="text-warning">27.11.2015, 15:00</small>
</div>
</div>
</li>
<li class="notification-box bg-gray">
<div class="row">
<div class="col-lg-3 col-sm-3 col-3 text-center">
<img src="/demo/man-profile.jpg" class="w-50 rounded-circle">
</div>
<div class="col-lg-8 col-sm-8 col-8">
<strong class="text-info">David John</strong>
<div>
Lorem ipsum dolor sit amet, consectetur
</div>
<small class="text-warning">27.11.2015, 15:00</small>
</div>
</div>
</li>
<li class="notification-box">
<div class="row">
<div class="col-lg-3 col-sm-3 col-3 text-center">
<img src="/demo/man-profile.jpg" class="w-50 rounded-circle">
</div>
<div class="col-lg-8 col-sm-8 col-8">
<strong class="text-info">David John</strong>
<div>
Lorem ipsum dolor sit amet, consectetur
</div>
<small class="text-warning">27.11.2015, 15:00</small>
</div>
</div>
</li>
<li class="drop-footer bg-dark text-center">
<a href="" class="text-light">View All</a>
</li>
</ul>
</li>
以下是Codepen的链接,其中一个页面存在此问题 - 图标不起作用,因此&#34;通知&#34;不存在的图片旁边是相关的下拉列表。 https://codepen.io/redheadedmandy/pen/ZxmxgN
答案 0 :(得分:2)
使用bootstrap预定义类.position-相对于ul list下拉菜单。检查下面的codepen工作演示。
<!-- top nav -->
<div class="mainnav">
<nav class="navbar">
<form class="form-inline right-align">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
<ul class="navbar-nav main-ul">
<li class="nav-item dropdown dropper">
<a class="nav-link text-light" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-bell">Notifications</i>
</a>
<ul class="dropdown-menu position-relative">
<li class="head text-light bg-dark">
<div class="row">
<div class="col-lg-12 col-sm-12 col-12">
<span>Notifications (3)</span>
<a href="" class="float-right">Mark all as read</a>
</div>
</li>
<li class="notification-box">
<div class="row">
<div class="col-lg-3 col-sm-3 col-3 text-center">
<img src="/demo/man-profile.jpg" class="w-50 rounded-circle">
</div>
<div class="col-lg-8 col-sm-8 col-8">
<strong class="text-info">David John</strong>
<div>
Lorem ipsum dolor sit amet, consectetur
</div>
<small class="text-warning">27.11.2015, 15:00</small>
</div>
</div>
</li>
<li class="notification-box bg-gray">
<div class="row">
<div class="col-lg-3 col-sm-3 col-3 text-center">
<img src="/demo/man-profile.jpg" class="w-50 rounded-circle">
</div>
<div class="col-lg-8 col-sm-8 col-8">
<strong class="text-info">David John</strong>
<div>
Lorem ipsum dolor sit amet, consectetur
</div>
<small class="text-warning">27.11.2015, 15:00</small>
</div>
</div>
</li>
<li class="notification-box">
<div class="row">
<div class="col-lg-3 col-sm-3 col-3 text-center">
<img src="/demo/man-profile.jpg" class="w-50 rounded-circle">
</div>
<div class="col-lg-8 col-sm-8 col-8">
<strong class="text-info">David John</strong>
<div>
Lorem ipsum dolor sit amet, consectetur
</div>
<small class="text-warning">27.11.2015, 15:00</small>
</div>
</div>
</li>
<li class="drop-footer bg-dark text-center">
<a href="" class="text-light">View All</a>
</li>
</ul>
</li>
<li class="nav-item pic-dropper">
<a href="#" class="nav-link" id="dropdownMenuButton" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img src="images/prof-pic.jpg" class="profpic float-right" alt="Profile picture"></a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
<h6 class="dropdown-header">Dropdown header</h6>
<div class="dropdown-divider"></div>
<ul class="notification-list">
<li class="notification-item">
</li>
</ul>
</div>
</li>
</ul>
</nav>
</div>