Container
Fundamental layout element that contains, pads, and centers content within a given viewport.
Overview
<Container> is the most basic layout element in Chassis. It contains, pads, and (sometimes) centers the content inside it. A <Grid> works with or without one around it. Containers can be nested, though most layouts don't need a nested container.
Chassis comes with three container variants:
<Container>, which sets amax-widthat each responsive breakpoint<Container fluid>, which iswidth: 100%at all breakpoints<Container fluidUntil={breakpoint}>, which iswidth: 100%until the specified breakpoint
Each variant's max-width follows a different pattern across breakpoints, shown here against the plain <Container> and <Container fluid> baselines.
| Extra sm <576px | Small ≥576px | Medium ≥768px | Large ≥1024px | X-Large ≥1280px | 2x-Large ≥1536px | |
|---|---|---|---|---|---|---|
<Container> | 100% | 540px | 720px | 960px | 1200px | 1440px |
<Container fluidUntil="sm"> | 100% | 540px | 720px | 960px | 1200px | 1440px |
<Container fluidUntil="md"> | 100% | 100% | 720px | 960px | 1200px | 1440px |
<Container fluidUntil="lg"> | 100% | 100% | 100% | 960px | 1200px | 1440px |
<Container fluidUntil="xl"> | 100% | 100% | 100% | 100% | 1200px | 1440px |
<Container fluidUntil="2xl"> | 100% | 100% | 100% | 100% | 100% | 1440px |
<Container fluid> | 100% | 100% | 100% | 100% | 100% | 100% |
Default container
The default <Container> class is a responsive, fixed-width container — its max-width changes at each breakpoint.
import { Container } from '@chassis-ui/react'
export const Example = () => {
return <Container>Default container</Container>
}Responsive containers
<Container fluidUntil={breakpoint}> renders full width until the given breakpoint is reached, then applies a max-width at that breakpoint and every larger one. <Container fluidUntil="sm">, for example, stays 100% wide until the sm breakpoint, then scales up through md, lg, xl, and 2xl.
import { Container } from '@chassis-ui/react'
export const Example = () => {
return (
<>
<Container fluidUntil="sm">100% wide until sm breakpoint</Container>
<Container fluidUntil="md">100% wide until md breakpoint</Container>
<Container fluidUntil="lg">100% wide until lg breakpoint</Container>
<Container fluidUntil="xl">100% wide until extra lg breakpoint</Container>
<Container fluidUntil="2xl">100% wide until extra extra lg breakpoint</Container>
</>
)
}Fluid containers
Use <Container fluid> for a full width container, spanning the entire width of the viewport.
import { Container } from '@chassis-ui/react'
export const Example = () => {
return <Container fluid>Fluid container</Container>
}API
Container
| Prop | Type | Default |
|---|---|---|
asChild? | boolean | — |
Render the single child element in place of this component's own element, with this
component's classes, props and ref merged onto it: <Button asChild><Link href="/login">Log
in</Link></Button>. The alternative to component for React Server Components — an element
can be passed from the server to this package's client components, a component reference
(component={Link}) can't. | ||
className? | string | — |
| A string of all className you want applied to the base component. | ||
component? | ElementType | — |
| Component used for the root node. Either a string to use a HTML element or a component. | ||
fluid? | boolean | — |
| Set container 100% wide, spanning the entire width of the viewport. | ||
fluidUntil? | Breakpoint | — |
Set container 100% wide until the given breakpoint, after which it scales up with max-width
at every larger breakpoint. | ||
ref? | any | — |