Containers
The contain class in Elevate is a utility for centering elements with consistent, responsive padding. It simplifies layouts by removing the need for bulky wrappers or custom styles, providing an elegant way to maintain evenly distributed containers across screen sizes.
Why Use Contain?
In traditional web development, creating centered containers often requires extra wrapper elements, manual padding adjustments, or repeated CSS rules for different screen sizes. These methods can become messy and hard to maintain.
The contain class resolves these issues by:
- Consistency Across Breakpoints: Padding values are managed via a central file and applied via a single class, ensuring a unified layout regardless of screen size.
- Simplicity: The class generates all necessary CSS automatically, reducing boilerplate and making your codebase cleaner.
How It Works
The contain class is defined in elevate/core/system/etc/contain.ts
, where breakpoints map to spacing tokens:
Example
For the lg
breakpoint:
- Breakpoint:
lg
(min-width: 1024px
). - Spacing:
d8
(2rem
).
Generated CSS:
This automation ensures:
- No Manual CSS Rules: The system creates all responsive styles for you.
- Consistency: All containers adhere to a unified padding scale, ensuring that content is visually balanced across screen sizes.
Simplified, Evenly Distributed Layouts
The contain class is especially useful for:
- Centering Content: Perfect for layouts like headers, footers, or sections that need consistent horizontal padding.
- Responsive Design: Adapts padding dynamically based on screen size.
- Cleaner Markup: Avoids unnecessary wrapper elements, reducing complexity in your HTML.
For example:
This approach centers the container on the screen and ensures that the content will not get too close to the edges.