0
0
SASSmarkup~20 mins

Grid column generator with loops in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Grid Column Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
1:30remaining
What is the output CSS of this SASS loop?
Given the following SASS code, what CSS rule will be generated for .col-3?
SASS
@for $i from 1 through 4 {
  .col-#{$i} {
    grid-column: span $i;
  }
}
A.col-3 { grid-column: span 4; }
B.col-3 { grid-column: 3; }
C.col-3 { grid-column: span 3; }
D.col-3 { grid-column: span $i; }
Attempts:
2 left
💡 Hint
Look at how the loop variable $i is used inside the selector and property.
🧠 Conceptual
intermediate
1:00remaining
How many CSS classes are generated by this SASS code?
Consider this SASS code snippet:
@for $col from 1 through 6 {
  .grid-col-#{$col} {
    grid-column: span $col;
  }
}

How many CSS classes will be generated?
A6
B5
C7
D4
Attempts:
2 left
💡 Hint
The loop runs from 1 through 6 inclusive.
selector
advanced
2:00remaining
Which option correctly generates grid columns with a gap using SASS loops?
You want to create grid column classes with a gap of 1rem between columns. Which SASS code snippet correctly applies the gap only between columns, not after the last column?
A
@for $i from 1 through 4 {
  .col-#{$i} {
    grid-column: span $i;
    margin-right: 1rem;
  }
}
B
@for $i from 1 through 4 {
  .col-#{$i} {
    grid-column: span $i;
    margin-right: 1rem;
  }
  .col-4 {
    margin-right: 0;
  }
}
C
@for $i from 1 through 4 {
  .col-#{$i} {
    grid-column: span $i;
  }
  .col-#{$i}:last-child {
    margin-right: 0;
  }
}
D
@for $i from 1 through 4 {
  .col-#{$i}:not(:last-child) {
    margin-right: 1rem;
  }
  .col-#{$i} {
    grid-column: span $i;
  }
}
Attempts:
2 left
💡 Hint
Think about how to remove margin from the last column only.
rendering
advanced
1:30remaining
What visual layout results from this CSS grid with generated columns?
Given this CSS generated by SASS:
.col-1 { grid-column: span 1; }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

If you place three divs with classes col-1, col-2, and col-3 inside .grid-container, how will they be arranged?
AThe first div takes 1 column, second takes 2 columns, third takes 3 columns, causing the third to wrap to next row.
BAll divs fit in one row because grid-template-columns allows infinite columns.
CThe divs overlap because grid-column spans exceed total columns.
DThe divs stack vertically ignoring grid-column spans.
Attempts:
2 left
💡 Hint
Remember the container has 4 equal columns and spans add up to more than 4.
accessibility
expert
2:30remaining
Which approach improves accessibility when generating grid columns with SASS loops?
You generate grid column classes with SASS loops for a responsive layout. Which option best improves accessibility for keyboard users and screen readers?
AAdd <code>tabindex="0"</code> to all grid items so they are focusable.
BUse semantic HTML elements inside grid items and add <code>aria-label</code> describing content.
CAdd <code>role="grid"</code> to container and <code>role="gridcell"</code> to each grid item.
DUse only <code>div</code> elements with no ARIA roles or labels for simplicity.
Attempts:
2 left
💡 Hint
Think about semantic meaning and meaningful labels for assistive technologies.