function
@function contrast-color($background-color, $light-color, $dark-color) { … }
Color
Name | Description | Type | Default Value |
---|---|---|---|
$background-color | Color | — | |
$light-color | Color | — | |
$dark-color | Color | — |
@use "@react-md/core";
$background-color: #fafafa;
.container {
background-color: $background-color;
color: core.contrast-color($background-color);
}
Gets the contrast between two colors. The contrast ratios between background and foreground colors should be:
NOTE: This does not account for font size or font weight but should be good enough for most cases.
The color with the highest contrast ratio
The background color to check
The light text color to use if it has a better contrast ratio.
The dark text color to use if it has a better contrast ratio.