docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
Build a Sass utility that calculates grid cell widths and protects against column overflow for responsive layouts.
Create a Sass function library that calculates cell widths for a responsive grid system supporting three device types: desktop (12 columns), tablet (8 columns), and phone (4 columns). The system must prevent layout breaks by clamping spans that exceed available columns.
Support three device types:
Your Sass module must provide functions that:
Validate and clamp column spans - Ensure a requested span doesn't exceed the device's maximum columns. If it does, return the device's column count instead.
Calculate Flexbox widths - Compute percentage-based widths using the formula: calc(100% / columns * span - gutter). This supports browsers that use Flexbox for grid rendering.
Calculate CSS Grid spans - Return the appropriate span value for CSS Grid's grid-column-end: span N property, ensuring it doesn't exceed available columns.
Generate device-specific results - Given a requested span, return calculated values for a specific device type, including both Flexbox width and Grid span.
// Returns the clamped span value (maximum of device columns)
// $requested-span: number - The desired column span
// $device: string - Device type ('desktop', 'tablet', or 'phone')
// Returns: number - Clamped span value
@function clamp-span($requested-span, $device) { }
// Calculates Flexbox width using calc(100% / columns * span - gutter)
// $span: number - The column span (should already be clamped)
// $device: string - Device type ('desktop', 'tablet', or 'phone')
// Returns: string - CSS calc() expression for width
@function get-flexbox-width($span, $device) { }
// Returns CSS Grid span value (minimum of span and device columns)
// $span: number - The column span
// $device: string - Device type ('desktop', 'tablet', or 'phone')
// Returns: number - Safe grid span value
@function get-grid-span($span, $device) { }
// Returns map with both Flexbox width and Grid span for a device
// $requested-span: number - The desired column span
// $device: string - Device type ('desktop', 'tablet', or 'phone')
// Returns: map - (flexbox-width: <calc-string>, grid-span: <number>)
@function calculate-cell-width($requested-span, $device) { }Provides responsive grid layout system with column-based layouts across multiple device breakpoints.