Atlaslog
Atlaslog / Field Notes / Leaflet containers & layers
Field note · Leaflet containers & layers

Flex layout collapses the map to zero height

Quick answer

The container is set to height: 100% inside a flex column whose height is content-driven, so the percentage resolves to auto and the map measures 0 pixels tall. Tiles are squeezed into one strip while centre and zoom stay correct.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Leaflet
Symptom
Checklist
  1. Walk up from #map printing clientHeight and computed display until the first zero-height ancestor.
  2. Check whether html and body both have height: 100%.
  3. Check whether the flex child lacks min-height: 0.
  4. Check whether the map was initialised while the panel was hidden.
Fix

Give html, body and .layout height: 100%, set the map wrapper to flex: 1 1 auto with min-height: 0 and position: absolute inset: 0 on #map, then call map.invalidateSize({ animate: false }) from a ResizeObserver.

Code
console.log(map.getSize());
// Point {x: 1280, y: 0}
var el = document.getElementById('map');
var node = el;
while (node && node !== document.documentElement) {
  console.log(node.tagName, node.className, node.clientHeight, getComputedStyle(node).display);
  node = node.parentElement;
}
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). Flex layout collapses the map to zero height. https://www.jingweizhi.com/en/cookbook/leaflet-flex-height-zero.html (accessed 2026-11-03).