2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Use @each to Map Over Items in a List
|
|
|
|
---
|
|
|
|
## Use @each to Map Over Items in a List
|
|
|
|
|
2019-03-09 01:03:18 -06:00
|
|
|
The @each directive loops over a list and for each iteration the variable is assigned the value in the list.
|
|
|
|
|
|
|
|
## Example:
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-03-09 01:03:18 -06:00
|
|
|
```html
|
Added SASS solutions, fixed typos, code formatting (#34792)
* Added SASS solution and output CSS
* Fixed typo, added code formatting
The example code outputs for "start to end" and "start through end" were swapped. "1 to 3" does not include the end number, so should output "1 2", while "1 through 3" includes the end number, so should output "1 2 3"
* Added SASS solution and output CSS
* Added SASS solution
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator [suggestion](https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979).
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979.
* Fixed Markdown syntax
Minor edit
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#discussion_r263731937.
2019-03-09 00:37:52 +09:00
|
|
|
<style type='text/sass'>
|
|
|
|
|
2019-03-09 01:03:18 -06:00
|
|
|
@each $color in white, black, blue {
|
|
|
|
.#{$color}-font {
|
|
|
|
color: $color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<div class="white-font"></div>
|
|
|
|
<div class="black-font"></div>
|
|
|
|
<div class="blue-font"></div>
|
|
|
|
```
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
|
|
|
```html
|
|
|
|
<style type='text/sass'>
|
|
|
|
|
Added SASS solutions, fixed typos, code formatting (#34792)
* Added SASS solution and output CSS
* Fixed typo, added code formatting
The example code outputs for "start to end" and "start through end" were swapped. "1 to 3" does not include the end number, so should output "1 2", while "1 through 3" includes the end number, so should output "1 2 3"
* Added SASS solution and output CSS
* Added SASS solution
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator [suggestion](https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979).
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979.
* Fixed Markdown syntax
Minor edit
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#discussion_r263731937.
2019-03-09 00:37:52 +09:00
|
|
|
@each $color in blue, black, red {
|
|
|
|
.#{$color}-bg {background-color: $color;}
|
|
|
|
}
|
|
|
|
|
|
|
|
div {
|
|
|
|
height: 200px;
|
|
|
|
width: 200px;
|
|
|
|
}
|
2019-03-09 01:03:18 -06:00
|
|
|
|
Added SASS solutions, fixed typos, code formatting (#34792)
* Added SASS solution and output CSS
* Fixed typo, added code formatting
The example code outputs for "start to end" and "start through end" were swapped. "1 to 3" does not include the end number, so should output "1 2", while "1 through 3" includes the end number, so should output "1 2 3"
* Added SASS solution and output CSS
* Added SASS solution
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator [suggestion](https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979).
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979.
* Fixed Markdown syntax
Minor edit
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#discussion_r263731937.
2019-03-09 00:37:52 +09:00
|
|
|
</style>
|
2018-10-12 15:37:13 -04:00
|
|
|
|
Added SASS solutions, fixed typos, code formatting (#34792)
* Added SASS solution and output CSS
* Fixed typo, added code formatting
The example code outputs for "start to end" and "start through end" were swapped. "1 to 3" does not include the end number, so should output "1 2", while "1 through 3" includes the end number, so should output "1 2 3"
* Added SASS solution and output CSS
* Added SASS solution
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator [suggestion](https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979).
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979.
* Fixed Markdown syntax
Minor edit
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#discussion_r263731937.
2019-03-09 00:37:52 +09:00
|
|
|
<div class="blue-bg"></div>
|
|
|
|
<div class="black-bg"></div>
|
|
|
|
<div class="red-bg"></div>
|
|
|
|
```
|
|
|
|
|
|
|
|
The solution above will generate the following CSS:
|
|
|
|
|
|
|
|
```css
|
|
|
|
.blue-bg {
|
|
|
|
background-color: blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
.black-bg {
|
|
|
|
background-color: black;
|
|
|
|
}
|
|
|
|
|
|
|
|
.red-bg {
|
|
|
|
background-color: red;
|
|
|
|
}
|
|
|
|
|
|
|
|
div {
|
|
|
|
height: 200px;
|
|
|
|
width: 200px;
|
|
|
|
}
|
|
|
|
```
|