For example Lets create an alert box, so for this we define the base styles; some padding , a border and background.
To start with it, we have to set out the list of colors and name variations of the alert box. Then count the number of variations using the length() function.
@colors : #ED5565, #A0D468, #F6BB42, #5D9CEC;
@names : error, success, attention, info;
@length : length(@colors);
Now define a loop:-
.alert-variation(@names; @colors; @index) when (iscolor(extract(@colors, @index))) and (@index > 0) {
.alert-variation(@names; @colors; (@index - 1)); // decrement.
}
@names: this variable is used to pass on the list of alert name variations.
@colors: this variable will pass the color codes of each respective name on the @nameslist.
@index: this variable will pass the number of names and colors we have within the list, and which we will also use for iterating the loop.
Now define the rule
.alert-variation(@names; @colors; @index) when (iscolor(extract(@colors, @index))) and (@index > 0) {
.alert-variation(@names; @colors; (@index - 1)); // decrement.
@name : extract(@names, @index);
@color : extract(@colors, @index);
.alert-@{name} {
border-color: darken(@color, 10%);
color: darken(@color, 30%);
background-color: @color;
}
}
We set the loop with inputs;-
.alert-variation(@names; @colors; @length);
this will give the css output below:-
.alert-error {
border: #e8273b;
color: #99101f;
background-color: #ed5565;
}
.alert-success {
border: #87c940;
color: #537f24;
background-color: #a0d468;
}
.alert-attention {
border: #f4a911;
color: #986807;
background-color: #f6bb42;
}
.alert-info {
border: #2f80e7;
color: #12509e;
background-color: #5d9cec;
}
0 Comment(s)