Gives content a fluid padding. If viewport goes beyond the website's max width, the content stays centered.
:root { /* Website width */ --website-min-width: ; /* 👈 Unitless pixels */ --website-max-width: ; /* 👈 Unitless pixels */ /* Spacing */ --container-min-padding: var(); /* 👈 Use the space scale */ --container-max-padding: var(); /* 👈 Use the space scale */}Gives content a fluid padding. If viewport goes beyond the website's max width, the content stays centered.
<Container>Some content</Container>This page is wrapped in a <Container />. To see it in action, resize the window and see how the padding grows fluidly with viewport width. Also notice how the Container remains centered when the viewport goes beyond the website's max width of 1536px.
The Container component inherits the --content-max-width variable and has its own fluid space rule.
/* Website width */@layer base { :root { /* Editable website width values */ --content-min-width: 20; /* 20rem = 320px */ --content-max-width: 96; /* 96rem = 1536px */ }} /* Container Space */@layer components { :root { /* Editable container paddings */ --container-min-padding: var(--scale-4); /* 6px */ --container-max-padding: var(--scale-13); /* 32px */
/* Calculations */ --container-deltaY: calc(var(--container-max-padding) - var(--container-min-padding)); --container-gradient: calc(var(--container-deltaY) / var(--size-deltaX)); --container-intercept: calc(var(--container-min-padding) - (var(--container-gradient) * var(--content-min-width))); --container-padding-size: calc(var(--container-gradient) * 100vw + var(--container-intercept) * 1rem);
/* Container fluid padding */ --container-padding-x: clamp(calc(var(--container-min-padding) * 1rem), var(--container-padding-size), calc(var(--container-max-padding) * 1rem));
/* Container max width */ --container-max-width: calc(var(--content-max-width) * 1rem); }}From which the max-w-container and *-container space utilities are created.
export const extendedTheme = { /* Website width */ maxWidth: { container: 'var(--container-max-width)', }, /* Space scale */ spacing: { container: 'var(--container-padding-x)', },}Even thought the *-container space utility works with all the properties that accept a size value, such as padding, margin, width, minWidth, maxWidth, height, minHeight, maxHeight, gap, inset, space, translate, scrollMargin, and scrollPadding, it should probably only be used for the Container component.
/* ### Layout ### */@layer components { /* Container. The container's class is called 'container-class' because TailwindCSS already has a 'container' class. */ .container-class { @apply max-w-container mx-auto w-full px-container; }}Unfortunately, TailwindCSS already has a container class, so we had to name ours container-class.