导航栏按钮图标颜色

导航栏按钮图标颜色

本文介绍了如何更改 Bootstrap 4 导航栏按钮图标颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Bootstrap 网站,当屏幕尺寸小于 992 像素时,它会添加汉堡切换器.代码是这样的:

I have a Bootstrap website where the hamburger toggler is added when the screen size is less than 992px. The code is like so:

<button class="navbar-toggler navbar-toggler-right"
        type="button" data-toggle="collapse"
        data-target="#navbarSupportedContent"
        aria-controls="navbarSupportedContent"
        aria-expanded="false"
        aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
</button>

有没有可能改变汉堡切换按钮的颜色?

Is there any possibility to change the color of the hamburger toggler button?

推荐答案

Bootstrap 4 中的 navbar-toggler-icon(汉堡包)使用 SVG background-image.切换器图标图像有 2 个版本".一个用于浅色导航栏,一个用于深色导航栏...

The navbar-toggler-icon (hamburger) in Bootstrap 4 uses an SVG background-image. There are 2 "versions" of the toggler icon image. One for a light navbar, and one for a dark navbar...

  • 使用 navbar-dark 在较暗的背景上设置浅色/白色切换器
  • 使用 navbar-light 在较亮的背景上设置暗/灰色切换器
  • Use navbar-dark for a light/white toggler on darker backgrounds
  • Use navbar-light for a dark/gray toggler on lighter backgrounds
// 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)' 值:

Therefore, if you want to change the color of the toggler image to something else, you can customize the icon. For example, here I set the RGB value to pink (255,102,203). Notice the stroke='rgba(255,102,203, 0.5)' value in the SVG data:

.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

OFC,另一种仅使用来自另一个库的图标的选项,即:Font Awesome 等.

OFC, another option to just use an icon from another library ie: Font Awesome, etc..

更新 Bootstrap 4.0.0:

从 Bootstrap 4 Beta 开始,navbar-inverse 现在是 navbar-dark 用于背景颜色较深的导航栏,以产生较浅的链接和切换器颜色.

As of Bootstrap 4 Beta, navbar-inverse is now navbar-dark to use on navbars with darker background colors to produce lighter link and toggler colors.

如何更改 Bootstrap 4 导航栏颜色

这篇关于如何更改 Bootstrap 4 导航栏按钮图标颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:17