本文介绍了Bootstrap 4:为什么在可滚动下拉列表中弹出窗口没有显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让它像Bootstrap 3一样工作。当我在悬停弹出窗口上有滚动条的下拉列表时,我认为Bootstrap 4存在问题。我需要溢出:隐藏;制作下拉滚动,但也隐藏了弹出窗口。我试图使用容器:'body'
但它没有用。
I want this to work just like Bootstrap 3. When I have a dropdown with scrollbar on hover popover, and I think there is a problem with Bootstrap 4. I need overflow:hidden; to make the dropdown scroll, but the popover is hidden too. I tried to use container:'body'
but it didn't work.
$(document).ready(function() {
$('[data-toggle="popover"]').popover({
html: true,
container: 'body'
});
});
.dropdown-menu{
height: 150px;
overflow: hidden;
overflow-y: auto
}
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Dropdowns</h2>
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
Dropdown button
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" title="Header" data-toggle="popover" data-placement="right" data-trigger="hover"data-content="Some content">Link 1</a></a>
<a class="dropdown-item" href="#" title="Header" data-toggle="popover" data-placement="right" data-trigger="hover" data-content="Some content">Link 2</a>
<a class="dropdown-item" href="#">Link 3</a>
<a class="dropdown-item" href="#">Link 4</a>
<a class="dropdown-item" href="#">Link 5</a>
<a class="dropdown-item" href="#">Link 6</a>
<a class="dropdown-item" href="#">Link 7</a>
<a class="dropdown-item" href="#">Link 8</a>
<a class="dropdown-item" href="#">Link 9</a>
</div>
</div>
</div>
推荐答案
popper.js
,以及它如何定位下拉列表,弹出窗口和工具提示。解决方案是将弹出窗口上的 数据边界
选项设置为窗口
。 。
There are some issues with popper.js
, and how it positions dropdowns, popovers and tooltips. The solution is to set the data-boundary
option on the popovers to window
...
$(document).ready(function() {
$('[data-toggle="popover"]').popover({
});
});
.dropdown-menu{
height: 150px;
overflow: hidden;
overflow-y: auto
}
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Dropdowns</h2>
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
Dropdown button
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" title="Header" data-boundary="window" data-toggle="popover" data-placement="right" data-trigger="hover"data-content="Some content">Link 1</a></a>
<a class="dropdown-item" href="#" title="Header" data-boundary="window" data-toggle="popover" data-placement="right" data-trigger="hover" data-content="Some content">Link 2</a>
<a class="dropdown-item" href="#">Link 3</a>
<a class="dropdown-item" href="#">Link 4</a>
<a class="dropdown-item" href="#">Link 5</a>
<a class="dropdown-item" href="#">Link 6</a>
<a class="dropdown-item" href="#">Link 7</a>
<a class="dropdown-item" href="#">Link 8</a>
<a class="dropdown-item" href="#">Link 9</a>
</div>
</div>
</div>
这篇关于Bootstrap 4:为什么在可滚动下拉列表中弹出窗口没有显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!