Utvikling · verktøy

CSS-generator for Grid og Flexbox

Velg Grid eller Flexbox, og angi layout-egenskapene for å lage CSS du kan kopiere.

Kjøres i nettleseren. Ingen opplasting.

Values are processed locally in this browser.

Result

—

Om verktøyet

CSS-generator for Grid og Flexbox sem complicação.

Verktøyet lager et CSS-kodeutdrag, ikke en hel side. Test brytpunkter og innholdsstørrelser i ditt eget design før publisering.

Veiledning

Slik bruker du CSS-generator for Grid og Flexbox

The CSS Grid and Flexbox Generator writes a short block of CSS for a layout of equal columns. You pick Grid or Flexbox, a number of columns from 1 to 12, a gap in pixels and a vertical alignment, then copy the result. It writes one rule for a container class, not a full page, and it makes no rows, areas, breakpoints or HTML.

Slik gjør du

  1. Choose the layout type: CSS Grid or Flexbox. Grid sets equal columns on the container. Flexbox lets items wrap and gives each item a share of the row width.
  2. Enter the number of columns as a whole number from 1 to 12. The box starts at 3. In Flexbox mode this number decides how wide each item is.
  3. Set the gap in pixels, from 0 to 200, and pick Start, Center, End or Stretch for the alignment. The alignment becomes the align-items value.
  4. Press Calculate, read the CSS in the result box and press Copy result. Rename the .container selector to match your own HTML, then test it with real content.

Eksempler

Three equal Grid columns

Du skriver inn
Oppsettstype
grid
Kolonner
3
Avstand
16
Justering
stretch
Du får
CSS
.container { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; }

Grid mode writes one rule. The repeat(3, minmax(0, 1fr)) part makes three columns that share the free width equally.

Kjørt med verktøyets egen kode.

A centred Flexbox row

Du skriver inn
Oppsettstype
flex
Kolonner
3
Avstand
16
Justering
center
Du får
CSS
.container { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; } .container > * { flex: 1 1 33.33%; }

Flexbox mode adds a second rule for the children. Each child gets a basis of 100 divided by 3, rounded to 33.33%.

Kjørt med verktøyets egen kode.

Seven items, no gap

Du skriver inn
Oppsettstype
flex
Kolonner
7
Avstand
0
Justering
start
Du får
CSS
.container { display: flex; flex-wrap: wrap; gap: 0px; align-items: start; } .container > * { flex: 1 1 14.29%; }

100 divided by 7 is 14.2857 and so on, written as 14.29%. A gap of zero is still written out as 0px.

Kjørt med verktøyets egen kode.

Too many columns

Du skriver inn
Oppsettstype
grid
Kolonner
13
Avstand
16
Justering
end
Du får
Melding
Use 1–12 columns, a 0–200px gap and a supported alignment.

Thirteen columns is above the limit, so the tool shows a message in place of CSS. A decimal such as 2.5 columns is refused the same way.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Start a card grid with a fixed number of columns without typing the declarations by hand.
  • Show a student how the same column count looks in Grid and in Flexbox.
  • Make a quick snippet for a prototype or a bug report, then rename the class.
  • Check what a chosen gap and alignment look like in code before editing a real stylesheet.

Begrensninger

  • It writes one rule for a class called .container. There are no rows, named areas, spanning items, breakpoints or media queries, and you must change the selector yourself.
  • Columns must be a whole number from 1 to 12, the gap must be from 0 to 200 pixels and the alignment must be one of four words. Anything else gives a message instead of CSS.
  • In Flexbox mode each item gets a basis of 100 divided by the column count and the gap is not subtracted. With a gap above zero the last item of a row can wrap to the next line, so test it in a browser.
  • The tool shows no preview and does not check browser support, so test the snippet with your real content and screen sizes.

Tips

  • Pick Grid when you want a strict number of equal columns, and Flexbox when the number of items varies and they should wrap.
  • Paste the snippet into your stylesheet, rename .container to a class that fits your page, then add your own rules for small screens.
  • If a Flexbox row wraps sooner than you expect, lower the flex basis in your own file or set the gap to 0 in the tool and add spacing another way.

Kilder

Vanlige spørsmål

Sobre CSS-generator for Grid og Flexbox.

How do I make a three-column layout with CSS Grid?

Choose CSS Grid, type 3 for the columns, set a gap and press Calculate. The result has display: grid and grid-template-columns: repeat(3, minmax(0, 1fr)). Copy it, rename .container to your own class and the children of that element fall into three equal columns.

What does minmax(0, 1fr) mean in the Grid result?

Each column takes an equal share of the free space, and the minimum of 0 lets a column shrink below the width of its content instead of pushing the grid wider than its box. The repeat() function writes that column rule once per column.

What is the difference between the Grid and the Flexbox output?

Grid output defines the columns on the container itself and lays every child into them. Flexbox output lets the children wrap and gives each one a width share through a second rule, so a row is built from item widths rather than from fixed columns.

What does the Alignment option change?

It sets the align-items property. In Grid it places each item inside its row area, and in Flexbox it places items inside their line. Stretch fills the height, while Start, Center and End position items at the top, middle or bottom.

Why does the last Flexbox item drop to the next line?

Each item is given a width of 100 divided by the column count, and the gap is added on top. Three items at 33.33% plus two gaps are wider than the container, so the third wraps. Reduce the basis in your own CSS or set the gap to zero.

Can this tool make rows, areas or responsive breakpoints?

No. It makes only equal columns with a gap and an alignment value. For named areas, spanning cells or media queries, write those parts by hand after you copy the snippet, and test the result in the browsers you care about.

Is my input uploaded anywhere?

No. The snippet is built in your browser from the four settings you choose, and nothing is sent to a server. The page does not store the values either, so refreshing it starts from the defaults.

Hvordan bruker du CSS-oppsettgenerator?

Velg Grid eller Flexbox, og angi layout-egenskapene for å lage CSS du kan kopiere.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.