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.
Symptom
- map.getSize() returns Point {x: 1280, y: 0}.
- Only the container border is visible, with tiles compressed into a single thin line.
- map.getCenter() and map.getZoom() return exactly the configured values.
Checklist
- Walk up from #map printing clientHeight and computed display until the first zero-height ancestor.
- Check whether html and body both have height: 100%.
- Check whether the flex child lacks min-height: 0.
- 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
- Setting #map { height: 100vh } under a 56 px header overflows the viewport and adds a scrollbar instead of fixing the layout.
- Creating the map inside a hidden tab and never calling invalidateSize leaves it drawing at the original zero size.
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
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).