Complete the code to define a simple grid container with flex display.
@mixin grid-container() {
display: [1];
flex-wrap: wrap;
}The grid container uses display: flex; to create a flexible layout that wraps items.
Complete the mixin to set the width of a grid column based on a fraction of total columns.
@mixin grid-column($span, $total-columns) {
width: ([1] / $total-columns) * 100%;
}The width is calculated by dividing the number of columns to span by the total columns, then converting to percentage.
Fix the error in the mixin to add gutter space between grid columns using margin.
@mixin grid-column($span, $total-columns, $gutter) {
width: calc( ( $span / $total-columns ) * 100% - [1] );
margin-right: $gutter;
}In Sass, to use a variable inside calc(), you must interpolate it with #{$variable}.
Fill both blanks to create a responsive grid column that adjusts width on smaller screens.
@mixin responsive-column($span, $total-columns, $gutter) {
width: calc( ( $span / $total-columns ) * 100% - [1] );
margin-right: $gutter;
@media (max-width: [2]) {
width: 100%;
margin-right: 0;
}
}The gutter variable is interpolated inside calc() for width calculation. The media query uses a max-width of 10rem for responsiveness.
Fill all three blanks to create a complete grid system mixin with container and column styles.
@mixin grid-system($total-columns, $gutter) {
display: [1];
flex-wrap: wrap;
margin-left: calc(-1 * [2]);
> * {
padding-left: [3];
}
}The container uses display: flex; and negative left margin equal to half the gutter to offset padding. Each child gets left padding of half the gutter for consistent spacing.