SASS | Список функций
Опубликовано: 2 Марта, 2022
Функции списков SASS используются для изменения новых списков. Списки должны быть созданы в круглых скобках, чтобы отличаться от других. Список SASS не может быть изменен, поэтому в некоторых случаях создаются новые списки.
Так же, как и строковые функции, списки SASS индексируются с единицей (а не с нуля), что означает, что первый элемент строки присутствует в индексе 1 (а не в индексе 0).
The following lists represents the all list functions in SASS:
- list-separator($list) function: This function returns the name of the separator used in the list as a string.
- Example 1:
list-separator((1,2,3)) - Output:
"comma"
- Example 2:
list-separator((123)) - Output:
"space"
- Example 1:
- zip($lists) function: This function devides the values of the lists given into a single multi-dimensional list.
- Example:
zip(1px2px3px,soliddasheddotted,redgreenblue) - Output:
1px solid red, 2px dashed green, 3px dotted blue
- Example:
- join($list1, $list2, [$separator]) function: This function appends $list2 to the end of $list1. The separator argument could contain the values “comma, space or auto”. The auto value, which is also the default value, will use the separator in the first list.
- Example 1:
join(123,456) - Output:
(1 2 3 4 5 6)
- Example 2:
join((1,2,3), (456), comma) - Output:
(1, 2, 3, 4, 5, 6)
- Example 3:
join((1,2,3), (456), space) - Output:
(1 2 3 4 5 6)
- Example 1:
- nth($list, $n) function: This function returns the nth element of the list.
- Example:
nth(5467891,4) - Output:
7
- Example:
- set-nth($list, $n, $value) function: This function sets the nth element of the list to the value provided.
- Example:
set-nth(5467891,3,5) - Output:
(5 4 5 7 8 9 1)
- Example:
- index($list, $value) function: This function returns the element at the specific index position called by value.
- Example:
index((5642397),4) - Output:
2
- Example:
- length($list) function: This function returns the number of elements in the list.
- Example:
length(5467891) - Output:
7
- Example:
- is-bracketed($list) function: This function checks whether the list has any square brackets or not.
- Example 1:
is-bracketed([a b c]) - Output:
true
- Example 2:
is-bracketed(a b c) - Output:
false
- Example 1:
- append($list1, $val, [$separator]) function: This function appends a single value provided to the end of the list. If the separator argument is provided (“auto” being the default separator), the complete list will follow the separator function.
- Example 1:
append((1,2,3),4, comma) - Output:
(1, 2, 3, 4)
- Example 2:
append((1,2,3),4, space) - Output:
(1 2 3 4)
- Example 1: