我的网站导航栏有问题。当我将导航栏展开时,它可以正常工作,但是当它处于折叠状态(适用于移动设备)时,导航栏中的下拉菜单项会将其他元素向左推,而忽略了代码(dropdown-menu-right)下拉菜单右对齐。
我不确定为什么要这样做。如果有人能找到解决方案,将不胜感激。
如果没有解决方案,我也想听听替代方法。
This is the closest i could find.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top border-bottom border-primary" id="main-nav">
<a href="index.html" class="navbar-brand">Project Name</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav flex-row d-sm-flex justify-content-around ml-sm-auto">
<li class="nav-item btn">
<a href="index.html" class="nav-link active"><i class="fas fa-home"></i> Home</a>
</li>
<li class="nav-item btn">
<a href="documentation/current/#" class="nav-link"><i class="fas fa-book"></i> Documentation</a>
</li>
<li class="nav-item dropdown btn">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-globe"></i> English
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<h1 class="dropdown-header">
<i class="fas fa-language fa-lg"></i> Language
</h1>
<div class="dropdown-divider"></div>
<a class="dropdown-item active" href="#">English</a>
<a class="dropdown-item disabled" href="#">Other Languages</a>
</div>
</li>
</ul>
</div>
</header>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
答案 0 :(得分:1)
设置dropdown-menu
.dropdown-menu{ position:absolute !important;}
(而不是!important
,我建议直接将样式应用于div
,以优先于Bootstrap的默认CSS)
答案 1 :(得分:0)
这对我有用
#dropdown-menu-align-right.dropdown-toggle::after{
margin:0px !important;
vertical-align: initial !important;
}
.dropdown-toggle[aria-expanded="true"]:after{
position:initial !important;
display:inline !important;
padding-right: 0px !important;
padding-bottom: 0px !important;
padding-top: 0px !important;
width: 0px !important;
min-width: 0rem !important;
padding-left: 4px !important;
margin:0ox !important;
}
.dropdown-toggle[aria-expanded="false"]:before{
padding-left: 4px !important;
padding-right: 0px !important;
padding-bottom: 0px !important;
padding-top: 0px !important;
position: initial !important;
display: inline !important;
width: 0px !important;
min-width: 0rem !important;
}