gpt4 book ai didi

css - 徽章增加导航栏高度

转载 作者:太空宇宙 更新时间:2023-11-03 22:17:54 27 4
gpt4 key购买 nike

我有以下用于 Bootstrap 导航栏的 HTML。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
/* Move down content because we have a fixed navbar that is 50px tall */

body {
padding-top: 33px;
padding-bottom: 20px;
}

.body {
font-size: 16px;
border-spacing: 2px;
border-collapse: separate;
text-align: center;
}

.body a {
text-decoration: underline;
}

.navbar-fixed-top {
background-color: #5b5b5b;
min-height: 33px;
border-style: none;
}

.navbar-toggle {
margin-top: 2px;
margin-bottom: 2px;
padding-top: 7px;
padding-bottom: 7px;
}

.navbar-nav>li>a {
line-height: 3px;
padding-top: 16px;
padding-bottom: 14px;
}

div.navbar-header>img {
height: 30px;
margin-top: 2px;
}

.nav>li>a {
font-size: medium;
font-family: "Helvetica Bold", sans-serif;
/*font-weight: bold;*/
text-transform: uppercase;
}

.navbar-inverse .navbar-nav>li>a {
color: #f0eed0;
}

.navbar-inverse .navbar-nav>li>a:hover {
color: #f8dc54;
}

.nav li {
display: inline;
}

#vugraph-menu.inprogress>a {
color: black;
background-color: #ecbe23;
}

#vugraph-menu.inprogress>a:hover,
#vugraph-menu.inprogress.open>a:not(:hover) {
color: white;
}
</style>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">

<div class="navbar-header">
<img src="http://www.bridgebase.com/images/bbo_red.png">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<div id="navbar" class="nav navbar-collapse collapse">
<div class="container">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Vugraph <span id="vugraph-count" class="badge badge-notify"></span></a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item"><a href="//www.bridgebase.com/v3/?vugraph=y" target="_blank">Watch</a></li>
<li class="dropdown-item"><a href="//www.bridgebase.com/vugraph/schedule.php" target="_blank">Schedule</a></li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a></li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a></li>
<li class="nav-item"><a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a></li>
</ul>
</div>
</div>
</div>
</nav>

没有徽章看起来像这样:

enter image description here

我有动态填充#vugraph-count 徽章的 JavaScript。当它有内容时,导航栏的高度增加超过 15 个像素。 HTML 变为:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
/* Move down content because we have a fixed navbar that is 50px tall */

body {
padding-top: 33px;
padding-bottom: 20px;
}

.body {
font-size: 16px;
border-spacing: 2px;
border-collapse: separate;
text-align: center;
}

.body a {
text-decoration: underline;
}

.navbar-fixed-top {
background-color: #5b5b5b;
min-height: 33px;
border-style: none;
}

.navbar-toggle {
margin-top: 2px;
margin-bottom: 2px;
padding-top: 7px;
padding-bottom: 7px;
}

.navbar-nav>li>a {
line-height: 3px;
padding-top: 16px;
padding-bottom: 14px;
}

div.navbar-header>img {
height: 30px;
margin-top: 2px;
}

.nav>li>a {
font-size: medium;
font-family: "Helvetica Bold", sans-serif;
/*font-weight: bold;*/
text-transform: uppercase;
}

.navbar-inverse .navbar-nav>li>a {
color: #f0eed0;
}

.navbar-inverse .navbar-nav>li>a:hover {
color: #f8dc54;
}

.nav li {
display: inline;
}

#vugraph-menu.inprogress>a {
color: black;
background-color: #ecbe23;
}

#vugraph-menu.inprogress>a:hover,
#vugraph-menu.inprogress.open>a:not(:hover) {
color: white;
}
</style>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">

<div class="navbar-header">
<img src="http://www.bridgebase.com/images/bbo_red.png">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<div id="navbar" class="nav navbar-collapse collapse">
<div class="container">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Vugraph <span id="vugraph-count" class="badge badge-notify">1</span></a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item"><a href="//www.bridgebase.com/v3/?vugraph=y" target="_blank">Watch</a></li>
<li class="dropdown-item"><a href="//www.bridgebase.com/vugraph/schedule.php" target="_blank">Schedule</a></li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a></li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a></li>
<li class="nav-item"><a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a></li>
</ul>
</div>
</div>
</div>
</nav>

渲染的导航栏看起来像:

enter image description here

(我必须将我们的自定义 CSS 内联到代码段的 HTML 框中,否则 bootstrap.min.css 会优先于自定义样式。)您需要使用堆栈片段的“整页”选项,用于获取未折叠的导航栏。

问题似乎与 .navbar-nav>li>a 样式 line-height: 3px 有关。当我删除它时,导航栏总是太高。这用于降低导航栏高度以匹配左侧的 Logo 。出于某种原因,当添加徽章时,它会覆盖它(尽管它没有在 DOM 检查器中被删除)。

最佳答案

badge 不是导致问题的原因,您可以检查下一个示例,其中有两个导航栏(一个带有带有数字的徽章,另一个没有),它们都具有相似的高度(如 Chris Bar 已指出)。所以:

1) 可能是你的一些自定义CSS有问题,这种情况下,我建议使用inspector工具来检查你添加了什么样式徽章导航栏

2) 您可以做的另一件事是检查您是否有结构良好的导航栏,如 Bootstrap Navbar 中所述。 .

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">

<!-- Brand and collapse button -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar1">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Navbar 1</a>
</div>

<div id="navbar1" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Vugraph
<span id="vugraph-count" class="no-padding badge badge-notify">99</span>
</a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item">
<a href="//www.bridgebase.com/v3/?vugraph=y" target="_blank">Watch</a>
</li>
<li class="dropdown-item">
<a href="//www.bridgebase.com/vugraph/schedule.php" target="_blank">Schedule</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a>
</li>
<li class="nav-item">
<a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a>
</li>
</ul>
</div>

</div>
</nav>

<nav class="navbar navbar-inverse navbar-fixed-bottom">
<div class="container">

<!-- Brand and collapse button -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar2">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Navbar 2</a>
</div>

<div id="navbar2" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Vugraph
<span id="vugraph-count" class="no-padding badge badge-notify"></span>
</a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item">
<a href="//www.bridgebase.com/v3/?vugraph=y" target="_blank">Watch</a>
</li>
<li class="dropdown-item">
<a href="//www.bridgebase.com/vugraph/schedule.php" target="_blank">Schedule</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a>
</li>
<li class="nav-item">
<a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a>
</li>
</ul>
</div>

</div>
</nav>

最后,我不认为更新到 Bootstrap 4 会有所帮助,事实上,您将不得不将整个站点移植到新版本,因为版本 发生了一些变化>34(阅读更多 here)。


更新

在使用元素上应用的自定义样式更新问题后,可能的解决方案是将下一个样式添加到 badge:

{line-height: 0; display: inline;}

示例:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
/* Move down content because we have a fixed navbar that is 50px tall */

#vugraph-count {
line-height: 0;
display: inline;
}

body {
padding-top: 33px;
padding-bottom: 20px;
}

.body {
font-size: 16px;
border-spacing: 2px;
border-collapse: separate;
text-align: center;
}

.body a {
text-decoration: underline;
}

.navbar-fixed-top {
background-color: #5b5b5b;
min-height: 33px;
border-style: none;
}

.navbar-toggle {
margin-top: 2px;
margin-bottom: 2px;
padding-top: 7px;
padding-bottom: 7px;
}

.navbar-nav>li>a {
line-height: 3px;
padding-top: 16px;
padding-bottom: 14px;
}

div.navbar-header>img {
height: 30px;
margin-top: 2px;
}

.nav>li>a {
font-size: medium;
font-family: "Helvetica Bold", sans-serif;
/*font-weight: bold;*/
text-transform: uppercase;
}

.navbar-inverse .navbar-nav>li>a {
color: #f0eed0;
}

.navbar-inverse .navbar-nav>li>a:hover {
color: #f8dc54;
}

.nav li {
display: inline;
}

#vugraph-menu.inprogress>a {
color: black;
background-color: #ecbe23;
}

#vugraph-menu.inprogress>a:hover,
#vugraph-menu.inprogress.open>a:not(:hover) {
color: white;
}
</style>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">

<div class="navbar-header">
<img src="http://www.bridgebase.com/images/bbo_red.png">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<div id="navbar" class="nav navbar-collapse collapse">
<div class="container">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Vugraph <span id="vugraph-count" class="badge badge-notify">1</span></a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item"><a href="//www.bridgebase.com/v3/?vugraph=y" target="_blank">Watch</a></li>
<li class="dropdown-item"><a href="//www.bridgebase.com/vugraph/schedule.php" target="_blank">Schedule</a></li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a></li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a></li>
<li class="nav-item"><a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a></li>
</ul>
</div>
</div>
</div>
</nav>

关于css - 徽章增加导航栏高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55480288/

27 4 0