我的html页面中有一个浮动按钮
.float{
position:fixed;
width:60px;
height:60px;
bottom:40px;
right:40px;
background-color:#0C9;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
}
.my-float{
margin-top:22px;
}
.label-container{
position:fixed;
bottom:48px;
right:105px;
display:table;
visibility: hidden;
}
.label-text{
color:#FFF;
background:rgba(51,51,51,0.5);
display:table-cell;
vertical-align:middle;
padding:10px;
border-radius:3px;
}
.label-arrow{
display:table-cell;
vertical-align:middle;
color:#333;
opacity:0.5;
}
.my-float{
font-size:24px;
margin-top:18px;
}
a.float + div.label-container {
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s ease;
}
a.float:hover + div.label-container{
visibility: visible;
opacity: 1;
}
a.float:hover .user-req-list {
visibility: collapse;
}
.float{
position:fixed;
width:60px;
height:60px;
bottom:40px;
right:40px;
background-color:#0C9;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
}
.my-float{
margin-top:22px;
}
.label-container{
position:fixed;
bottom:48px;
right:105px;
display:table;
visibility: hidden;
}
.label-text{
color:#FFF;
background:rgba(51,51,51,0.5);
display:table-cell;
vertical-align:middle;
padding:10px;
border-radius:3px;
}
.label-arrow{
display:table-cell;
vertical-align:middle;
color:#333;
opacity:0.5;
}
.my-float{
font-size:24px;
margin-top:18px;
}
a.float + div.label-container {
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s ease;
}
a.float:hover + div.label-container{
visibility: visible;
opacity: 1;
}
a.float:hover .user-req-list {
visibility: collapse;
}
<body>
<a class="float">
<i class="fa fa-plus my-float"></i>
</a>
<div class="label-container">
<div class="label-text">User Join Requests</div>
<i class="fa fa-play label-arrow"></i>
</div>
</body>
我想向该按钮添加一个下拉列表,因此当我在其上按/悬停该列表时,该列表将出现,用户将能够与其进行交互。 我尝试从here中看到的引导程序中添加一个下拉列表,但是如您在此处看到的那样,该列表未显示
.float{
position:fixed;
width:60px;
height:60px;
bottom:40px;
right:40px;
background-color:#0C9;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
}
.my-float{
margin-top:22px;
}
.label-container{
position:fixed;
bottom:48px;
right:105px;
display:table;
visibility: hidden;
}
.label-text{
color:#FFF;
background:rgba(51,51,51,0.5);
display:table-cell;
vertical-align:middle;
padding:10px;
border-radius:3px;
}
.label-arrow{
display:table-cell;
vertical-align:middle;
color:#333;
opacity:0.5;
}
.my-float{
font-size:24px;
margin-top:18px;
}
a.float + div.label-container {
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s ease;
}
a.float:hover + div.label-container{
visibility: visible;
opacity: 1;
}
a.float:hover .user-req-list {
visibility: collapse;
}
.user-req-list {
visibility: hidden;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="dropdown">
<a class="float dropdown-toggle" role="button" id="dropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<i class="fa fa-plus my-float"></i>
</a>
<div class="label-container">
<div class="label-text">User Join Requests</div>
<i class="fa fa-play label-arrow"></i>
</div>
<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>
如您所见,它不起作用,当我将鼠标悬停在按钮上时,该列表也不会显示。有什么办法可以做我想要的吗? 还请注意,我的项目使用的是角度6,因此所有javascript基本上都无法显示。
答案 0 :(得分:0)
实际上,您的代码正在运行。您只是没有为下拉菜单添加JS要求。 See documentation。
下拉菜单建立在第三方库Popper.js上,该库提供动态定位和视口检测。确保在Bootstrap的JavaScript之前包含popper.min.js或使用包含Popper.js的bootstrap.bundle.min.js / bootstrap.bundle.js。尽管不需要动态定位,但Popper.js并不用于在导航栏中定位下拉菜单。
不过,请注意,将鼠标悬停在下拉菜单上将无法访问该下拉列表。根据{{3}},这是documentation
.float{
position:fixed;
width:60px;
height:60px;
bottom:40px;
right:40px;
background-color:#0C9;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
}
.my-float{
margin-top:22px;
}
.label-container{
position:fixed;
bottom:48px;
right:105px;
display:table;
visibility: hidden;
}
.label-text{
color:#FFF;
background:rgba(51,51,51,0.5);
display:table-cell;
vertical-align:middle;
padding:10px;
border-radius:3px;
}
.label-arrow{
display:table-cell;
vertical-align:middle;
color:#333;
opacity:0.5;
}
.my-float{
font-size:24px;
margin-top:18px;
}
a.float + div.label-container {
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s ease;
}
a.float:hover + div.label-container{
visibility: visible;
opacity: 1;
}
a.float:hover .user-req-list {
visibility: collapse;
}
.user-req-list {
visibility: hidden;
}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="dropdown">
<a class="float dropdown-toggle" role="button" id="dropdownMenuButton" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<i class="fa fa-plus my-float"></i>
</a>
<div class="label-container">
<div class="label-text">User Join Requests</div>
<i class="fa fa-play label-arrow"></i>
</div>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<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>