CSS Flexbox-Generator

Bauen Sie Flexbox-Layouts visuell · passen Sie Container- und Item-Eigenschaften an, sehen Sie eine Live-Vorschau und kopieren Sie das CSS.

Container-Eigenschaften

Live-Vorschau

Generiertes CSS

So funktioniert es

  1. Container-Eigenschaften setzen: Konfigurieren Sie den Flex-Container, flex-direction, justify-content, align-items, flex-wrap und gap.
  2. Flex-Items hinzufügen und konfigurieren: Fügen Sie Kindelemente hinzu und legen Sie individuelle Werte für flex-grow, flex-shrink, flex-basis, align-self und order fest.
  3. CSS kopieren: Holen Sie sich das vollständige CSS für Container und Items, einsatzbereit für Ihr Projekt.

Warum den Flexbox-Generator nutzen?

Flexbox ist das wesentliche Werkzeug für eindimensionale CSS-Layouts, Elemente in einer Zeile oder Spalte ausrichten, mit kraftvollen Steuerungen für Verteilung und Ausrichtung. Doch die Eigenschaften sind zahlreich und ihr Zusammenspiel komplex: justify-content gegen align-items, flex-grow gegen flex-basis, Hauptachse gegen Querachse. Dieser interaktive Generator gibt sofortiges visuelles Feedback beim Umschalten jeder Eigenschaft, der schnellste Weg, Flexbox zu lernen und passendes CSS für Ihr Layout zu erhalten.

Funktionen

Häufige Fragen

Was ist der Unterschied zwischen justify-content und align-items?

justify-content verteilt Items entlang der Hauptachse (standardmäßig horizontal). align-items richtet Items entlang der Querachse aus (standardmäßig vertikal). Steht flex-direction auf column, vertauschen sich die Achsen, justify-content wird vertikal, align-items wird horizontal.

Wann sollte ich Flexbox und wann CSS Grid einsetzen?

Nutzen Sie Flexbox für eindimensionale Layouts, eine Reihe von Buttons, eine Navigationsleiste, eine Liste umbrechender Karten. Nutzen Sie CSS Grid für zweidimensionale Layouts, bei denen Sie Zeilen und Spalten gleichzeitig steuern müssen, etwa ein vollständiges Seitenlayout oder ein komplexes Karten-Raster.

Was bedeutet flex: 1?

flex: 1 ist die Kurzform für flex-grow: 1; flex-shrink: 1; flex-basis: 0%. Sie weist das Element an, den verfügbaren Platz zu füllen, bei Bedarf zu schrumpfen und vor der Verteilung mit Größe null zu starten. Alle Items mit flex: 1 teilen sich den Platz gleichmäßig.

Was ist Flexbox?

Flexbox (Flexible Box Layout) is a CSS layout model designed for distributing space and aligning items in a one-dimensional direction: either a row or a column. It introduces two core concepts that determine how everything behaves: the main axis (the primary direction items flow, horizontal by default) and the cross axis (perpendicular to main, vertical by default). Once you internalize main vs cross, every Flexbox property maps to one of them: justify-content works on the main axis, align-items works on the cross axis, flex-direction swaps which axis is which.

Flexbox solved a set of layout problems that plagued web developers from 1998 to 2014. Before Flexbox, centering an element vertically required hacks (display: table-cell, negative margins, position: absolute with translate transforms). Equal-height columns required the "faux columns" technique with background images. Sticky footers needed precise pixel calculations. Flexbox made all of these trivial: a one-line declaration replaces decades of CSS workarounds. The trade-off is that Flexbox is one-dimensional; for two-dimensional layouts (row AND column simultaneously), CSS Grid (shipped 2017) is the better tool.

Flexbox properties divide cleanly into two groups: container properties (applied to the parent: display: flex, flex-direction, flex-wrap, justify-content, align-items, align-content, gap) and item properties (applied to children: flex-grow, flex-shrink, flex-basis, align-self, order). The container properties control layout patterns; the item properties control individual exceptions. This generator surfaces both sets so you can experiment with how they interact without writing code.

Was im Generator steckt

The live preview is a flex container with sample child elements. As you change container properties (flex-direction, justify-content, etc.) via dropdowns and inputs, JavaScript updates the inline style of the preview container, and the browser re-renders the layout. The preview is the actual browser's Flexbox implementation, not a JavaScript simulation: you see exactly what your CSS will produce on a real page.

Per-item controls let you adjust each child individually. You can add or remove items, set their flex-grow, flex-shrink, flex-basis, align-self, and order values, and see how the container redistributes space accordingly. Visual axis indicators show the main and cross axes for the current configuration, reinforcing the mental model. The properties are real CSS that you can copy directly into your stylesheet, no transpilation or framework prefixes needed.

The Generated CSS panel updates with each interaction, producing two CSS rules: one for the container (with the chosen flex properties) and one for the items. Click Copy CSS and the rules are written to your clipboard. The tool itself never makes network requests; the preview rendering, code generation, and clipboard write all happen in JavaScript on your device. Refresh the page and your configuration is gone unless you copied the CSS first.

Geschichte und Hintergrund

Praktische Workflows

Haeufige Fallstricke

Datenschutz und Datenverarbeitung

CSS learning and layout tools come in two flavors: simple HTML pages running client-side JavaScript (private, fast, no setup) and cloud editors with saved projects (collaborative but with privacy trade-offs). This tool is the first kind. Your property selections, your item configurations, your generated CSS: all stay in your browser session. Refresh the page and the state is gone unless you copied the CSS first.

The privacy stakes are low here because Flexbox configurations rarely contain sensitive information. Still, the lack of analytics matters: you can experiment freely without your trial-and-error process being recorded. Particularly useful in classroom or corporate training settings where having students or trainees register accounts on third-party platforms is a friction point. The tool is a single static page with no backend, usable in any browser, including locked-down enterprise machines.

Wann Flexbox nicht zu verwenden ist

Mehr Fragen

What does the flex shorthand mean exactly?

The flex shorthand sets three properties at once: flex: <grow> <shrink> <basis>. Common values: flex: 1 (1, 1, 0%) for equal-distribution items, flex: 0 0 auto for fixed-size items, flex: 1 1 250px for items that grow/shrink from a 250px starting point. The shorthand has special initial values when only one or two values are provided; the explicit three-value form avoids surprises.

How do I make items wrap to multiple rows?

Set flex-wrap: wrap on the container. Items overflow to a new line when they don't fit. Combine with flex-basis on items to control how many fit per row: flex: 1 1 200px creates a responsive grid where items are at least 200px, grow to fill remaining space, and wrap to new rows on narrow screens. The container gap property handles spacing between wrapped rows and items.

Can I reverse the order of flex items?

Yes, multiple ways. Container-level: flex-direction: row-reverse (or column-reverse) reverses all items in order. Item-level: the order property assigns numeric weights; items with lower numbers appear first. Default order is 0; setting order: -1 on one item moves it to the front. Accessibility note: visual reordering doesn't affect tab order or screen-reader reading order, which can confuse keyboard and assistive-tech users. Use sparingly.

What is the difference between align-items and align-content?

align-items aligns items within their row (or column) along the cross axis. align-content aligns the rows (or columns) themselves within the container, only meaningful when there are multiple wrapped lines. If flex-wrap is set to nowrap (the default), align-content has no effect because there's only one line. Use align-items for single-line alignment, align-content for multi-line alignment.

How do I center a single element with Flexbox?

The classic answer: display: flex; justify-content: center; align-items: center; on the parent container. This centers the child both horizontally and vertically. For just horizontal: use justify-content: center only. For just vertical: use align-items: center only. If you need to center inside a parent of unknown height, add min-height: 100vh to the parent so it has vertical space to center within. The whole pattern replaces 20 years of CSS centering workarounds.

Why doesn't my text truncation work in a flex container?

Because of the min-width: auto default on flex items. Text-overflow: ellipsis requires the element to actually overflow its container; with the default minimum width set to the content's intrinsic size, the element never overflows. Fix: add min-width: 0 to the flex item containing the truncating text. This is the most common Flexbox bug Stack Overflow answers ever: searching "flex text-overflow ellipsis not working" returns thousands of versions of this exact answer.

Verwandte Tools