bootstrap V5导航栏:导航栏切换按钮应具有自定义的背景颜色、悬停背景颜色和悬停边框颜色,

5vf7fwbs  于 4个月前  发布在  Bootstrap
关注(0)|答案(1)|浏览(60)

先决条件

建议

V5 导航栏:导航栏切换按钮应具有自定义的 bg-color、hover-bg-color 和 hover-border-color

navbar.scss

.navbar {
  --#{$prefix}navbar-toggler-bg: #{$navbar-light-toggler-bg};
  --#{$prefix}navbar-toggler-hover-bg: #{$navbar-light-toggler-hover-bg};
  --#{$prefix}navbar-toggler-hover-border-color: #{$navbar-light-toggler-hover-border-color};
}

.navbar-toggler {
  background-color: var(--#{$prefix}navbar-toggler-bg);
  &:hover {
    background-color: var(--#{$prefix}navbar-toggler-hover-bg);
    border-color: var(--#{$prefix}navbar-toggler-hover-border-color);
  }
}

@include color-mode(dark) {
  .navbar {
    --#{$prefix}navbar-brand-color: #{$navbar-dark-brand-color};
    --#{$prefix}navbar-color: #{$navbar-dark-color};
    --#{$prefix}navbar-hover-color: #{$navbar-dark-hover-color};
    --#{$prefix}navbar-active-color: #{$navbar-dark-active-color};
    --#{$prefix}navbar-disabled-color: #{$navbar-dark-disabled-color};
  }

  .navbar-toggler {
    background-color: var(--#{$prefix}navbar-toggler-bg);
    &:hover {
      background-color: var(--#{$prefix}navbar-toggler-hover-bg);
      border-color: var(--#{$prefix}navbar-toggler-hover-border-color);
    }
  }
}

variables.scss

$navbar-light-icon-color: $white !default;
$navbar-light-toggler-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-light-icon-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>") !default;
$navbar-light-toggler-bg: $primary !default;
$navbar-light-toggler-hover-bg: shade-color($primary, 15%) !default;
$navbar-light-toggler-border-color: $primary !default;
$navbar-light-toggler-hover-border-color: shade-color($primary, 20%) !default;

variables-dark.scss

$navbar-dark-icon-color: $white !default;
$navbar-dark-toggler-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-dark-icon-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>") !default;
$navbar-dark-toggler-bg: $primary !default;
$navbar-dark-toggler-hover-bg: tint-color($primary, 15%) !default;
$navbar-dark-toggler-border-color: $primary !default;
$navbar-dark-toggler-hover-border-color: tint-color($primary, 10%) !default;

动机和背景

ve7v8dk2

ve7v8dk21#

如果能用CSS属性而不是Sass变量自定义颜色就更好了。目前$navbar-dark-icon-color被嵌入到$navbar-dark-toggler-icon-bg中。我曾经很幸运地让SVG成为一个mask,而不是一个background-image,然后你可以设置background-color

相关问题