WissensdatenbankPrüfungszentrum
DEDeutsch
Sprache wählen13

CKTIS / CSS

gap — CSS-Eigenschaft

`gap` setzt Zeilen- und Spaltenabstände in Grid-, Flex- und Mehrspaltenlayout.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

<'row-gap'> <'column-gap'>?

gap setzt Zeilen- und Spaltenabstände in Grid-, Flex- und Mehrspaltenlayout.

Das Beispiel nutzt einen umbrechenden Flex-Container und misst horizontalen und vertikalen Abstand getrennt.

Die akzeptierte Grammatik ist <'row-gap'> <'column-gap'>?; globale Werte nehmen weiterhin an der Kaskade teil.

In Flexbox folgt die Bedeutung von row-gap und column-gap der flex-direction; Prozentwerte können bei inhaltsabhängiger Größe zyklisch sein.

Beispiele

<!doctype html>
<html lang="en"><meta charset="utf-8"><title>CKTIS CSS reference example</title>
<body><div class="probe">probe</div><pre id="result"></pre><script>
document.body.innerHTML='<div id="g"><i></i><i></i><i></i><i></i></div><pre id="result"></pre>';const g=document.querySelector("#g");g.style.cssText="display:flex;flex-wrap:wrap;width:44px;gap:8px 4px";for(const x of g.children)x.style.cssText="width:20px;height:10px";const a=g.children[0].getBoundingClientRect(),b=g.children[1].getBoundingClientRect(),c=g.children[2].getBoundingClientRect();document.querySelector("#result").textContent="column-gap="+Math.round(b.left-a.right)+"; row-gap="+Math.round(c.top-a.bottom)+"; computed="+getComputedStyle(g).gap;
</script></body></html>

Ergebnis

column-gap=4; row-gap=8; computed=8px 4px

Das Beispiel lief lokal in einer isolierten Chrome-Sitzung ohne Netzwerk; das Ergebnis stammt aus der CSS-API des Browsers.

Quellen