Dev Helpers
← Back

Auto-fit content columns

Import and render <AutoFitContentColumns /> in a React project.

Open this example in the interactive library

Live preview

Source code

// components/AutoFitContentColumns.tsx

import type { ReactNode } from "react";

export default function AutoFitContentColumns({
  children = "Your content",
  aside = "Notes",
}: { children?: ReactNode; aside?: ReactNode } = {}) {
  return (
    <section
      style={{
        display: "grid",
        gap: "1rem",
        gridTemplateColumns: "repeat(auto-fit,minmax(min(100%,18rem),1fr))",
      }}
    >
      <article>{children}</article>
      <aside>{aside}</aside>
    </section>
  );
}