确实没有 Bootstrap 原生类或 mixin 来实现开箱即用。另一方面...... Bootsstrap 是为扩展而构建的:您可以使用 SASS 扩展 Bootstrap 并动态创建帮助程序类。
注意:下面的 SASS 代码示例是针对您的问题完成的(= 所有颜色 = 900 个额外的辅助类)。也许您可能希望通过仅将颜色类构建为您真正需要的颜色来减少大量额外的代码。请随时根据您的需要调整该代码。
//### make sure you have imported bootstrap function & variables first
@import 'functions';
@import 'variables';
//### SASS function to extend Bootstrap
//### --> quick and dirty demo example!!!
@mixin make-color-classes( $class_prefix, $color_name, $color ){
// note: positive values = tint | negative values = shade
$swatch_variations: (80%, 60%, 40%, 20%, 0, -20%, -40%, -60%, -80%);
$i: 1;
@each $variation in $swatch_variations {
// process bootstrap color
@if ($variation > 0){
$swatch_color: tint($color);
}@else if ($variation < 0) {
$variation: $variation * -1;
$swatch_color: shade($color);
}@else{
$swatch_color: $color;
}
// write class
$color_number: $i * 100;
.#{$class_prefix}-#{$color_name}-#{$color_number} {
color: tint-color($color, $variation );
}
$i: $i + 1;
}
}
//### NOW:
//### create helper classes for a single color
@include make-color-classes('text', 'blue', $blue);
//### NOW EXTENDED:
//### create helper classes for all named default bootstrap colors
$colors_to_use: $colors;
@each $color_name, $color in $colors_to_use {
@include make-color-classes('text', $color_name, $color);
}