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, click this checkbox , edit the values below, and 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
.
:root { /* Website width */ --website-min-width: ; /* 👈 Unitless pixels */ --website-max-width: ; /* 👈 Unitless pixels */ /* Spacing */ --container-min-padding: ; /* 👈 Unitless pixels */ --container-max-padding: ; /* 👈 Unitless pixels */}
import { type HTMLAttributes, type PropsWithChildren, forwardRef } from 'react'import { cn } from '#app/utils/tailwind-merge.ts'
/** * Container component. * * @component * @example * ```jsx * <Container>Some content</Container> * ``` * * @param {string} [className] - Additional CSS class names. * @param {React.HTMLAttributes<HTMLDivElement>} [props] - Additional HTML attributes. * @returns {JSX.Element} The Container component. */const Container = forwardRef<HTMLDivElement, PropsWithChildren<HTMLAttributes<HTMLDivElement>>>(({ className, ...props }, ref) => ( <div ref={ref} className={cn('container', className)} {...props} />))Container.displayName = 'Container'
export { Container }
.container { @apply max-w-website px-viewport-padding mx-auto w-full overflow-x-hidden;}