Bootstrap 4更改导航链接悬停颜色

时间:2018-06-22 11:07:07

标签: twitter-bootstrap sass bootstrap-4 themes

我正在使用Bootstrap 4和Sass(scss)创建一个网站。我遇到的问题是,导航栏中的链接是灰色的,而不是我想要的蓝色。

我可以找到的关于该主题的每个主题都建议覆盖导航项目的样式。我认为这会在以后开发时给您带来麻烦。因此,我更喜欢覆盖变量而不是样式,但是对于我来说,它在某种程度上无法正常工作。

我通过建议的方式覆盖了引导程序样式:

  • 使用颜色替换功能创建scss文件
  • 通过$theme-colors函数更改样式
  • bootstrap.scss文件之前导入主题文件。

我的_theme.scss如下:

@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";

$blue:      #0053CB;
$blue-700:  #0F2C92;
$white:     #FFFFFF;
$green:     #39CA71;
$red:       #F1453D;
$orange:    #fd7e14;
$yellow:    #FDC02F;

$gray-100:  rgba(0,0,0,.03);

$theme-colors: (
  primary: $blue,
  secondary: $white,
  light: $white,
  dark: $blue-700,
  success: $green,
  warning: $orange,
  danger: $red,
);

// Import bootstrap as last so that the variables will be overridden
@import '~bootstrap/scss/bootstrap';

$link-hover-color(用于导航链接)的引导程序代码如下:

$link-color:                theme-color("primary") !default;
$link-hover-color:          darken($link-color, 15%) !default;

问题是,例如,在我的html中使用bg-primary时,正确使用了我定义的主题颜色,但是悬停和链接颜色不是我期望的蓝色,而是默认的灰色。我的设置中是否缺少某些东西,或者我做错了什么?

1 个答案:

答案 0 :(得分:3)

$link-color$link-hover-color影响页面上的链接,但不影响Navbar导航链接,这些链接是通过$navbar-light-color和/或$navbar-dark-color变量专门设置的。这些是使用$ black或$ white的明暗度定义的,如您在variables.scss中所见。

因此,假设您希望在较浅的背景上使用蓝色(较暗)链接,则可能需要将Navbar导航链接颜色设置为...

$navbar-light-color: rgba($primary, .5);
$navbar-light-hover-color: rgba($primary, .7);
$navbar-light-active-color: rgba($primary, .9);

演示:https://www.codeply.com/go/66E7nUGVxD


以上是针对SASS的。您仍然只能使用CSS自定义导航栏:Bootstrap 4 navbar color

相关问题