Bootstrap 5 map for color levels - css

In Bootstrap 5 docs, _colors.scss has the following classes:
.bd-blue-100 { color: color-contrast($blue-100); background-color: $blue-100; }
.bd-blue-200 { color: color-contrast($blue-200); background-color: $blue-200; }
.bd-blue-300 { color: color-contrast($blue-300); background-color: $blue-300; }
.bd-blue-400 { color: color-contrast($blue-400); background-color: $blue-400; }
.bd-blue-500 { color: color-contrast($blue-500); background-color: $blue-500; }
.bd-blue-600 { color: color-contrast($blue-600); background-color: $blue-600; }
.bd-blue-700 { color: color-contrast($blue-700); background-color: $blue-700; }
.bd-blue-800 { color: color-contrast($blue-800); background-color: $blue-800; }
.bd-blue-900 { color: color-contrast($blue-900); background-color: $blue-900; }
.bd-indigo-100 { color: color-contrast($indigo-100); background-color: $indigo-100; }
.bd-indigo-200 { color: color-contrast($indigo-200); background-color: $indigo-200; }
.bd-indigo-300 { color: color-contrast($indigo-300); background-color: $indigo-300; }
.bd-indigo-400 { color: color-contrast($indigo-400); background-color: $indigo-400; }
.bd-indigo-500 { color: color-contrast($indigo-500); background-color: $indigo-500; }
.bd-indigo-600 { color: color-contrast($indigo-600); background-color: $indigo-600; }
.bd-indigo-700 { color: color-contrast($indigo-700); background-color: $indigo-700; }
.bd-indigo-800 { color: color-contrast($indigo-800); background-color: $indigo-800; }
.bd-indigo-900 { color: color-contrast($indigo-900); background-color: $indigo-900; }
.bd-purple-100 { color: color-contrast($purple-100); background-color: $purple-100; }
.bd-purple-200 { color: color-contrast($purple-200); background-color: $purple-200; }
.bd-purple-300 { color: color-contrast($purple-300); background-color: $purple-300; }
.bd-purple-400 { color: color-contrast($purple-400); background-color: $purple-400; }
.bd-purple-500 { color: color-contrast($purple-500); background-color: $purple-500; }
.bd-purple-600 { color: color-contrast($purple-600); background-color: $purple-600; }
.bd-purple-700 { color: color-contrast($purple-700); background-color: $purple-700; }
.bd-purple-800 { color: color-contrast($purple-800); background-color: $purple-800; }
.bd-purple-900 { color: color-contrast($purple-900); background-color: $purple-900; }
and so on...
Each color level is defined in _variables.scss
How to generate these classes with .scss loops and maps instead of manually writing each level for each color?

Related

Less inheritance doesn't work

Hi can you check please following code? I want define some styles for class, and next apply same styles for another class. I've used inheritance for that but styles from parent aren't used:
.parent-item {
&:not(:last-child) {
margin-right: 20px;
}
}
.child-item {
&:extend(.parent-item);
//...
}
just add the word all next to the name of the class
.child-item {
&:extend(.parent-item all);
//...
}
for example
.parent-item {
color: green;
background: red;
&:not(:last-child) {
margin-right: 20px;
}
&:last-child {
color: red;
}
&:hover {
color: red;
}
}
.child-item {
&:extend(.parent-item all);
//...
}
result will be
.parent-item,
.child-item {
color: green;
background: red;
}
.parent-item:not(:last-child),
.child-item:not(:last-child) {
margin-right: 20px;
}
.parent-item:last-child,
.child-item:last-child {
color: red;
}
.parent-item:hover,
.child-item:hover {
color: red;
}

Less extend multipling class names

I've a generic class like:
button {
color: dimgray;
& > * {
display: inline-block;
vertical-align: middle;
}
}
So i'm trying a simple extend:
button.new {
&:extend(button all);
color: green;
&:hover {
color: darkgreen;
}
}
Why i've a .new.new select in extended class?
button,
button.new {
color: dimgray;
}
button > *,
button.new > * {
display: inline-block;
vertical-align: middle;
}
button.new {
color: green;
}
button.new:hover,
button.new.new:hover {
color: darkgreen;
}
This is not correct i think, i'm using last version of less (js library)
button.new.new:hover

How to add a "modified" class for an element in SCSS

Given this scss
.root {
color: red;
&-child {
color: blue;
small & {
font-size: 80%;
}
}
}
This is the CSS I get:
.root {
color: red;
}
.root-child {
color: blue;
}
small .root-child {
font-size: 80%;
}
I want to style .root-child on small differently so the rule I need is:
small.root-child {
font-size: 80%;
}
(Notice no whitespace after small)
How can I do that?
You need to use #at-root and that will remove the white space in your selector, as well as it will be a valid syntax so no issues while you try to compile.
.root {
color: red;
&-child {
color: blue;
#at-root small#{&} {
font-size: 80%;
}
}
}
You can use #at-root like this:
SCSS
.root {
color: red;
&-child {
color: blue;
#at-root {
small#{&} {
font-size: 80%;
}
}
}
}
Compiled:
.root {
color: red;
}
.root-child {
color: blue;
}
small.root-child {
font-size: 80%;
}

SCSS child class over riding parent class

I have this:
tr {
&.selected {
background-color: #424253;
}
td {
&.current-month {
background-color: #2c3645;
}
&.last {
background-color: #1e252f;
font-weight: bold;
}
}
}
The rule in tr:
&.selected {
background-color: #424253;
}
As expected, is being overridden by the td rules:
&.current-month {
background-color: #2c3645;
}
&.last {
background-color: #1e252f;
font-weight: bold;
}
How do I make it so the tr class selected always overrules any td class affecting background-color (without using !important)?
You can give same specificity as the current-month and last classes and writing selected at the end will take more precision and overrides others.
tr {
td {
&.current-month {
background-color: #2c3645;
}
&.last {
background-color: #1e252f;
font-weight: bold;
}
&.selected {
background-color: #424253;
}
}
}
You could override the background for all td elements that have a class assigned:
tr {
&.selected {
background-color: #424253;
&[class] {
background-color: #424253;
}
}
td {
&.current-month {
background-color: #2c3645;
}
&.last {
background-color: #1e252f;
font-weight: bold;
}
}
}
but i also think in this case it would be totally ok to use !important.
Another solution, if you would use classes for tr and td elements would be this:
.table-row {
.table-cell {
&.current-month {
background-color: #2c3645;
}
&.last {
background-color: #1e252f;
font-weight: bold;
}
#at-root .selected#{&} {
background-color: #424253;
}
}
}

How can I combine classes on a button using .less?

I have this .less file for buttons:
button {
background: #button-background;
color: #text;
&.primary {
background-image: linear-gradient(#79d858, #569e3d);
border-color: #4a993e;
color: white;
}
&.primary:hover {
background-image: linear-gradient(#89e868, #66ae4d);
border-color: #4a993e;
color: white;
}
&.primary:active,
&.primary:focus {
background-image: linear-gradient(#99f878, #76be5d);
border-color: #4a993e;
color: white;
}
}
Can someone give me advice on how I can combine all the &.primary into one ?
Is this what you want:
button {
background: #button-background;
color: #text;
&.primary {
background-image: linear-gradient(#79d858, #569e3d);
border-color: #4a993e;
color: white;
&:hover {
background-image: linear-gradient(#89e868, #66ae4d);
}
&:active, &:focus {
background-image: linear-gradient(#99f878, #76be5d);
}
}
}
DEMO

Resources