Bootstrap 4中的navbar-toggler-icon
(汉堡包)使用SVG background-image
。该toggler图标图像有2个“版本”,一个用于浅色导航栏,另一个用于深色导航栏...
- 在较暗背景上使用
navbar-dark
以获得浅色/白色toggler
- 在较亮背景上使用
navbar-light
以获得深色/灰色toggler。
// this is a black icon with 50% opacity
.navbar-light .navbar-toggler-icon {
background-image: url("data:image/svg+xml;..");
}
// this is a white icon with 50% opacity
.navbar-dark .navbar-toggler-icon {
background-image: url("data:image/svg+xml;..");
}
因此,如果您想将切换器图像的颜色更改为其他颜色,可以自定义图标。例如,在这里我将RGB值设置为粉色(255,102,203)。请注意SVG数据中
stroke='rgba(255,102,203, 0.5)'
的值:
.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='rgba(255,102,203, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}
.custom-toggler.navbar-toggler {
border-color: rgb(255,102,203);
}
演示 http://www.codeply.com/go/4FdZGlPMNV
当然,还有另一种选择,就是直接使用其他库中的图标,比如Font Awesome等。
更新Bootstrap 4.0.0:
从Bootstrap 4 Beta开始,navbar-inverse
现在变成了navbar-dark
,用于具有较暗背景颜色的导航栏,以产生更浅的链接和切换器颜色。
如何更改Bootstrap 4导航栏颜色