Bootstrap 4 导航栏切换器未显示 [英] Bootstrap 4 navbar toggler not showing
问题描述
这是我第一次尝试使用 Bootstrap 4 测试版.我现在在 BS3 中创建并运行了一个慈善团体网站.我正在使用固定的顶部导航栏和自定义 CSS.当网站以较小的形式查看时,而不是全屏显示时,切换图标不会显示.你能帮助我吗?我希望它像导航链接一样是白色的,悬停将链接更改为阅读.这是头部链接
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous"><!-- 此模板的自定义样式--><link href="css/custombs4.css" rel="样式表">`
页面底部链接js代码
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF593hXpGoriK"cross匿名"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqKaISfwNz4M" crossorigin="anonymous"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4N.;
这是我的代码.
/* 导航栏 */.navbar-custom {背景色:#3193de;}/* 改变品牌和文字颜色 */.navbar-custom .navbar-brand,.navbar-custom .navbar-text {文字装饰:无;颜色:#fff;}/* 更改链接颜色 */.navbar-custom .navbar-nav .nav-link {文字装饰:无;颜色:#fff;}/* 更改活动或悬停链接的颜色 */.navbar-custom .nav-item.active .nav-link,.navbar-custom {文字装饰:无;颜色:#fff;}.nav-item .nav-link:hover {文字装饰:无;颜色:#ff0000;}/* 仅用于下拉菜单 - 更改下拉菜单的颜色 */.navbar-custom .dropdown-menu {背景色:#3193de;}.navbar-custom .dropdown-item {文字装饰:无;颜色:#fff;}.navbar-custom .dropdown-item:hover,.navbar-custom .dropdown-item:focus {文字装饰:无;颜色:#ff0000;背景色:#3193de;}.navbar-header .navbar-toggler {边框:0;}.navbar-toggler-icon {颜色:#fff;}.navbar-toggler-icon:hover {背景:#ff0000;}
</nav>
页面在这里http://ahepa215.org/navbar-top-fixed.html
@mlegg,由于 id
属性的值与 button
上的 >data-toggler 属性.下面的代码显示了它应该是什么.
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false"aria-label="切换导航"><span class="navbar-toggler-icon"></span>按钮><div class="collapse navbar-collapse" id="navbarCollapse">
至于切换图标的样式,您可以使用以下代码:
.navbar-toggler-icon {背景图像:url("数据:图像/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpathstroke='rgba(255,255,255, 1)'stroke-width='2'stroke-linecap='round'stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");}
要彻底了解这里发生的事情,请在此堆栈溢出中查看@ZimSystem 的答案问题.最终,您必须在 background-image
的 URL 中设置 stroke 属性的值,如下所示:
stroke='rgba(255,255,255, 1)'
检查这个 codeply 项目
This is my first attempt with Bootstrap 4 beta. I have a charity group website I made up and running in BS3 now. I am using a fixed top navbar and custom CSS. When the site is viewed smaller, not full screen, the toggle icon doesn't show up. Can you help me? I want it to be white like the nav links, and hover changes the link to read. This is the head links
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link href="css/custombs4.css" rel="stylesheet"> `
the js codes are linked at the bottom of the page
<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.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
Here is my code.
/* Navbar */
.navbar-custom {
background-color: #3193de;
}
/* change the brand and text color */
.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
text-decoration: none; color: #fff;
}
/* change the link color */
.navbar-custom .navbar-nav .nav-link {
text-decoration: none; color: #fff;
}
/* change the color of active or hovered links */
.navbar-custom .nav-item.active .nav-link,
.navbar-custom {
text-decoration: none; color: #fff;
}
.nav-item .nav-link:hover {
text-decoration: none; color: #ff0000;
}
/* for dropdown only - change the color of dropdown */
.navbar-custom .dropdown-menu {
background-color: #3193de;
}
.navbar-custom .dropdown-item {
text-decoration: none; color: #fff;
}
.navbar-custom .dropdown-item:hover,
.navbar-custom .dropdown-item:focus {
text-decoration: none; color: #ff0000;
background-color:#3193de;
}
.navbar-header .navbar-toggler {
border: 0;
}
.navbar-toggler-icon {
color: #fff;
}
.navbar-toggler-icon:hover {
background: #ff0000;
}
<nav class="navbar navbar-custom navbar-expand-md">
<a class="navbar-brand" href="#">AHEPA 215</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-custom" aria-controls="navbar-custom" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">About</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#">AHEPA</a>
<a class="dropdown-item" href="#">Chapter 215 Brothers</a>
</li>
<li class="nav-item">
<a class="nav-link" href="scholarship.html">Scholarships</a>
</li>
<li class="nav-item">
<a class="nav-link" href="photos.html">Photos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="join.html">Join</a>
</li>
<li class="nav-item">
<a class="nav-link" href="calendar.html">Calendar</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.html">Contact</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="https://www.facebook.com/portsmouth.ahepa" target="_blank"><i class="fa fa-facebook"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="mailto:ahepa215@gmail.com"><i class="fa fa-envelope"></i></a>
</li>
</ul>
</div>
</nav>
the page is live here http://ahepa215.org/navbar-top-fixed.html
@mlegg, your toggler icon isn't toggling as a result of the id
attribute not having the same value as the data-toggler
attribute on your button
. The code below shows what it should be.
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
As for the styling of the toggle icon, you can with the following code:
.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='rgba(255,255,255, 1)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}
For a thorough understanding of what's happening here, checkout @ZimSystem's answer in this stack overflow question. Ultimately, you have to set the value of the stroke property in the URL of the background-image
like so:
stroke='rgba(255,255,255, 1)'
Checkout this codeply project
这篇关于Bootstrap 4 导航栏切换器未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!