我正在尝试在导航栏的右侧添加一些填充,当我在Chrome中重新加载页面时,名称位于1行上,向下箭头位于名称下方的行上。
当我单击它时,问题将完全解决,直到下一次重新加载或调整大小为止。我曾尝试使用Firefox,但没有遇到相同的问题,Firefox上的一切正常。
我想知道每当我在Chrome中重新加载页面时是否有办法摆脱这个问题?
此外,还有其他方法可以将右侧的导航项向左移动一点而不使用填充吗?
当下拉菜单的名称太短(如5或6个字符)时,菜单仅显示其中的一部分,我该如何放置菜单?
在Chrome上重新加载页面时出现的问题:
当您单击菜单时问题消失了:
该问题不在Firefox上
这是我的代码
<style>
#zzz {
padding-right: 1.5%;
}
.navbar-brand {
padding-left: 1.5% ;
}
.nav-link {
color: #b7c9cc;
}
ul.navbar-nav a:hover {
color: white;
}
.navbar-nav > li > .dropdown-menu > .dropdown-item:hover {
background-color: #202e3e;
}
navbar-tooggler {
color: white;
}
.custom-toggler.navbar-toggler {
border-color: transparent;
outline: none;
}
.custom-toggler .navbar-toggler-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='white' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}
</style>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sth</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fullwidth">
<nav class="navbar navbar-expand-lg" style="background-color: #202e3e">
<a class="navbar-brand" href="#">
<img src="./assets/logo.png" width="32" height="32" alt="">
</a>
<button class="navbar-toggler custom-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Nav<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Nav</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Nav</a>
</li>
</ul>
<!-- -->
<ul class="navbar-nav" id="zzz">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown Menu
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Something</a>
<a class="dropdown-item" href="#">Something</a>
<a class="dropdown-item" href="#">Something</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Log Out</a>
</div>
</li>
</ul>
<!-- -->
</div>
</nav>
</div>
</body>
</html>
答案 0 :(得分:1)
对于填充,请使用px而不是%
#zzz {
padding-right: 10px;
}
关于第二个问题,因为您正在使用引导程序,所以它带有它自己的CSS,它使菜单一直对齐到边缘。您添加它以解决该问题。
.dropdown-menu {
right: 0;
left: inherit;
}
答案 1 :(得分:-1)
请在代码的以下行尝试“文本右移”:
<ul class="navbar-nav" id="zzz">.
它应该看起来像:
<ul class="navbar-nav text-right" id="zzz">
请尝试发布您的发现。