3.9 KiB
3.9 KiB
id, title, challengeType, forumTopicId, localeTitle
| id | title | challengeType | forumTopicId | localeTitle |
|---|---|---|---|---|
| 587d7dbe367417b2b2512bb9 | Use @for to Create a Sass Loop | 0 | 301462 | Используйте @ для создания петли Sass |
Description
@for добавляет стили в цикле, очень похожие for цикл for в JavaScript. @for используется двумя способами: «начать с конца» или «начать с конца». Основное различие заключается в том, что «начало к концу» исключает конечный номер, а «начало через конец» включает конечный номер. Вот начало через конец , например: @for $ i от 1 до 12 {Часть
.col - # {$ i} {width: 100% / 12 * $ i; }
}
#{$i} - это синтаксис для объединения переменной ( i ) с текстом для создания строки. Когда файл Sass преобразуется в CSS, он выглядит так: .col-1 {Это мощный способ создания сетки. Теперь у вас есть двенадцать вариантов ширины столбцов, доступных как классы CSS.
ширина: 8,33333%;
}
.col-2 {
ширина: 16,66667%;
}
...
.col-12 {
ширина: 100%;
}
Instructions
@for которая принимает переменную $j которая идет от 1 до 6. Она должна создать 5 классов с именем .text-1 to .text-5 где каждый имеет font-size установленный в 10px, умноженный на индекс.
Tests
tests:
- text: Your code should use the <code>@for</code> directive.
testString: assert(code.match(/@for /g));
- text: Your <code>.text-1</code> class should have a <code>font-size</code> of 10px.
testString: assert($('.text-1').css('font-size') == '10px');
- text: Your <code>.text-2</code> class should have a <code>font-size</code> of 20px.
testString: assert($('.text-2').css('font-size') == '20px');
- text: Your <code>.text-3</code> class should have a <code>font-size</code> of 30px.
testString: assert($('.text-3').css('font-size') == '30px');
- text: Your <code>.text-4</code> class should have a <code>font-size</code> of 40px.
testString: assert($('.text-4').css('font-size') == '40px');
- text: Your <code>.text-5</code> class should have a <code>font-size</code> of 50px.
testString: assert($('.text-5').css('font-size') == '50px');
Challenge Seed
<style type='text/sass'>
</style>
<p class="text-1">Hello</p>
<p class="text-2">Hello</p>
<p class="text-3">Hello</p>
<p class="text-4">Hello</p>
<p class="text-5">Hello</p>
Solution
<style type='text/sass'>
@for $i from 1 through 5 {
.text-#{$i} { font-size: 10px * $i; }
}
</style>
<p class="text-1">Hello</p>
<p class="text-2">Hello</p>
<p class="text-3">Hello</p>
<p class="text-4">Hello</p>
<p class="text-5">Hello</p>
<style type='text/sass'>
@for $i from 1 to 6 {
.text-#{$i} { font-size: 10px * $i; }
}
</style>
<p class="text-1">Hello</p>
<p class="text-2">Hello</p>
<p class="text-3">Hello</p>
<p class="text-4">Hello</p>
<p class="text-5">Hello</p>