mirror of https://github.com/twbs/bootstrap.git
Improve gradients
- Use a semitransparent gradient from light to dark which works on any background-color - Store the gradient as a custom property (--bs-gradient) - Remove `.bg-gradient-*` variants in favour of `.bg-gradient` which works even when `$enable-gradients` are enabled - Add gradients to navbar, active page links and badges when gradients are enabled
This commit is contained in:
parent
bbeda10e37
commit
b531bda07c
|
@ -14,6 +14,7 @@
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
vertical-align: baseline;
|
vertical-align: baseline;
|
||||||
@include border-radius($badge-border-radius);
|
@include border-radius($badge-border-radius);
|
||||||
|
@include gradient-bg();
|
||||||
|
|
||||||
// Empty badges collapse automatically
|
// Empty badges collapse automatically
|
||||||
&:empty {
|
&:empty {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
@import "helpers/background";
|
|
||||||
@import "helpers/clearfix";
|
@import "helpers/clearfix";
|
||||||
@import "helpers/colored-links";
|
@import "helpers/colored-links";
|
||||||
@import "helpers/embed";
|
@import "helpers/embed";
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
@import "mixins/table-variants";
|
@import "mixins/table-variants";
|
||||||
|
|
||||||
// Skins
|
// Skins
|
||||||
@import "mixins/background-variant";
|
|
||||||
@import "mixins/border-radius";
|
@import "mixins/border-radius";
|
||||||
@import "mixins/box-shadow";
|
@import "mixins/box-shadow";
|
||||||
@import "mixins/gradients";
|
@import "mixins/gradients";
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
.nav-link.active,
|
.nav-link.active,
|
||||||
.show > .nav-link {
|
.show > .nav-link {
|
||||||
color: $nav-pills-link-active-color;
|
color: $nav-pills-link-active-color;
|
||||||
background-color: $nav-pills-link-active-bg;
|
@include gradient-bg($nav-pills-link-active-bg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
padding-right: $navbar-padding-x; // default: null
|
padding-right: $navbar-padding-x; // default: null
|
||||||
padding-bottom: $navbar-padding-y;
|
padding-bottom: $navbar-padding-y;
|
||||||
padding-left: $navbar-padding-x; // default: null
|
padding-left: $navbar-padding-x; // default: null
|
||||||
|
@include gradient-bg();
|
||||||
|
|
||||||
// Because flex properties aren't inherited, we need to redeclare these first
|
// Because flex properties aren't inherited, we need to redeclare these first
|
||||||
// few properties so that content nested within behave properly.
|
// few properties so that content nested within behave properly.
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
&.active .page-link {
|
&.active .page-link {
|
||||||
z-index: 3;
|
z-index: 3;
|
||||||
color: $pagination-active-color;
|
color: $pagination-active-color;
|
||||||
background-color: $pagination-active-bg;
|
@include gradient-bg($pagination-active-bg);
|
||||||
border-color: $pagination-active-border-color;
|
border-color: $pagination-active-border-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,4 +12,5 @@
|
||||||
// See https://github.com/sass/sass/issues/2383#issuecomment-336349172
|
// See https://github.com/sass/sass/issues/2383#issuecomment-336349172
|
||||||
--bs-font-sans-serif: #{inspect($font-family-sans-serif)};
|
--bs-font-sans-serif: #{inspect($font-family-sans-serif)};
|
||||||
--bs-font-monospace: #{inspect($font-family-monospace)};
|
--bs-font-monospace: #{inspect($font-family-monospace)};
|
||||||
|
--bs-gradient: #{$gradient};
|
||||||
}
|
}
|
||||||
|
|
|
@ -416,6 +416,11 @@ $utilities: map-merge(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
"gradient": (
|
||||||
|
property: background-image,
|
||||||
|
class: bg,
|
||||||
|
values: (gradient: var(--bs-gradient))
|
||||||
|
),
|
||||||
"white-space": (
|
"white-space": (
|
||||||
property: white-space,
|
property: white-space,
|
||||||
class: text,
|
class: text,
|
||||||
|
|
|
@ -222,6 +222,11 @@ $enable-negative-margins: false !default;
|
||||||
$enable-deprecation-messages: true !default;
|
$enable-deprecation-messages: true !default;
|
||||||
$enable-important-utilities: true !default;
|
$enable-important-utilities: true !default;
|
||||||
|
|
||||||
|
// Gradient
|
||||||
|
//
|
||||||
|
// The gradient which is added to components if `$enable-gradients` is `true`
|
||||||
|
// This gradient is also added to elements with `.bg-gradient`
|
||||||
|
$gradient: linear-gradient(180deg, rgba($white, .15), rgba($white, 0)) !default;
|
||||||
|
|
||||||
// Spacing
|
// Spacing
|
||||||
//
|
//
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
|
|
||||||
&[type="checkbox"] {
|
&[type="checkbox"] {
|
||||||
@if $enable-gradients {
|
@if $enable-gradients {
|
||||||
background-image: escape-svg($form-check-input-checked-bg-image), linear-gradient(180deg, lighten($form-check-input-checked-bg-color, 10%), $form-check-input-checked-bg-color);
|
background-image: escape-svg($form-check-input-checked-bg-image), var(--bs-gradient);
|
||||||
} @else {
|
} @else {
|
||||||
background-image: escape-svg($form-check-input-checked-bg-image);
|
background-image: escape-svg($form-check-input-checked-bg-image);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
|
|
||||||
&[type="radio"] {
|
&[type="radio"] {
|
||||||
@if $enable-gradients {
|
@if $enable-gradients {
|
||||||
background-image: escape-svg($form-check-radio-checked-bg-image), linear-gradient(180deg, lighten($form-check-input-checked-bg-color, 10%), $form-check-input-checked-bg-color);
|
background-image: escape-svg($form-check-radio-checked-bg-image), var(--bs-gradient);
|
||||||
} @else {
|
} @else {
|
||||||
background-image: escape-svg($form-check-radio-checked-bg-image);
|
background-image: escape-svg($form-check-radio-checked-bg-image);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
border-color: $form-check-input-indeterminate-border-color;
|
border-color: $form-check-input-indeterminate-border-color;
|
||||||
|
|
||||||
@if $enable-gradients {
|
@if $enable-gradients {
|
||||||
background-image: escape-svg($form-check-input-indeterminate-bg-image), linear-gradient(180deg, lighten($form-check-input-checked-bg-color, 10%), $form-check-input-checked-bg-color);
|
background-image: escape-svg($form-check-input-indeterminate-bg-image), var(--bs-gradient);
|
||||||
} @else {
|
} @else {
|
||||||
background-image: escape-svg($form-check-input-indeterminate-bg-image);
|
background-image: escape-svg($form-check-input-indeterminate-bg-image);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
@if $enable-gradients {
|
|
||||||
@each $color, $value in $theme-colors {
|
|
||||||
@include bg-gradient-variant(".bg-gradient-#{$color}", $value);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
// stylelint-disable declaration-no-important
|
|
||||||
|
|
||||||
@mixin bg-gradient-variant($parent, $color) {
|
|
||||||
#{$parent} {
|
|
||||||
background-image: linear-gradient(180deg, mix($body-bg, $color, 15%), $color) !important;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -97,7 +97,7 @@
|
||||||
border-color: $color;
|
border-color: $color;
|
||||||
|
|
||||||
&:checked {
|
&:checked {
|
||||||
@include gradient-bg(lighten($color, 10%), escape-svg($form-check-input-checked-bg-image));
|
background-color: $color;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus {
|
&:focus {
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
// Gradients
|
// Gradients
|
||||||
|
|
||||||
@mixin gradient-bg($color, $foreground: null) {
|
@mixin gradient-bg($color: null) {
|
||||||
@if $enable-gradients {
|
|
||||||
@if $foreground {
|
|
||||||
background-image: $foreground, linear-gradient(180deg, mix($body-bg, $color, 15%), $color);
|
|
||||||
} @else {
|
|
||||||
background-image: linear-gradient(180deg, mix($body-bg, $color, 15%), $color);
|
|
||||||
}
|
|
||||||
} @else {
|
|
||||||
background-color: $color;
|
background-color: $color;
|
||||||
|
|
||||||
|
@if $enable-gradients {
|
||||||
|
background-image: var(--bs-gradient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ Changes to our source Sass files and compiled CSS.
|
||||||
- `color-yiq()` function and related variables are renamed to `color-contrast()` since it's not related to YIQ colorspace anymore. [See #30168.](https://github.com/twbs/bootstrap/pull/30168/)
|
- `color-yiq()` function and related variables are renamed to `color-contrast()` since it's not related to YIQ colorspace anymore. [See #30168.](https://github.com/twbs/bootstrap/pull/30168/)
|
||||||
- `$yiq-contrasted-threshold` is renamed `$min-contrast-ratio`.
|
- `$yiq-contrasted-threshold` is renamed `$min-contrast-ratio`.
|
||||||
- `$yiq-text-dark` and `$yiq-text-light` are respectively renamed `$color-contrast-dark` and `$color-contrast-light`.
|
- `$yiq-text-dark` and `$yiq-text-light` are respectively renamed `$color-contrast-dark` and `$color-contrast-light`.
|
||||||
|
- Linear gradients are simplified when gradients are enabled and therefore, `gradient-bg()` now only accepts an optional `$color` parameter.
|
||||||
|
- `bg-gradient-variant()` mixin is removed since the `.bg-gradient` class can now be used to add gradients to elements instead of the `.bg-gradient-*` classes.
|
||||||
|
|
||||||
## JavaScript
|
## JavaScript
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,14 @@ Similar to the contextual text color classes, easily set the background of an el
|
||||||
|
|
||||||
## Background gradient
|
## Background gradient
|
||||||
|
|
||||||
When `$enable-gradients` is set to `true` (default is `false`), you can use `.bg-gradient-` utility classes. [Learn about our Sass options]({{< docsref "/customize/sass" >}}) to enable these classes and more.
|
By adding a `.bg-gradient` class, a linear gradient is added as background image to the backgrounds. This gradient starts with a semi-transparent white which fades out to the bottom.
|
||||||
|
|
||||||
|
Do you need a gradient in your custom CSS? Just add `background-image: var(--bs-gradient);`.
|
||||||
|
|
||||||
{{< markdown >}}
|
{{< markdown >}}
|
||||||
{{< colors.inline >}}
|
{{< colors.inline >}}
|
||||||
{{- range (index $.Site.Data "theme-colors") }}
|
{{- range (index $.Site.Data "theme-colors") }}
|
||||||
- `.bg-gradient-{{ .name }}`
|
<div class="p-3 mb-2 bg-{{ .name }} bg-gradient {{ if or (eq .name "light") (eq .name "warning") }}text-dark{{ else }}text-white{{ end }}">.bg-{{ .name }}.bg-gradient</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{< /colors.inline >}}
|
{{< /colors.inline >}}
|
||||||
{{< /markdown >}}
|
{{< /markdown >}}
|
||||||
|
|
Loading…
Reference in New Issue