From 023b8a7e5047934871018d5d86a3fecc02837134 Mon Sep 17 00:00:00 2001 From: Martin Rubli Date: Tue, 7 Nov 2023 22:19:13 +0100 Subject: [PATCH] static: css: Fix map tile offset for maps with Tailwind Typography MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Embedding a Leaflet map within a Tailwind Typography-styled
leads to a very subtle (the higher the zoom the subtler) vertical map offset. It is particularly noticeable in combination with track overlays where tracks and map are suddenly misaligned. The root cause is this part of the Tailwind-generated stylesheet: .prose :where(img):not(:where([class~=not-prose],[class~=not-prose] *)) { margin-top: 2em; margin-bottom: 2em } It adds a 2em margin to all element and, because Leaflet tiles are images, that leads to a vertical offset. The obvious solution is to not embed maps in a
. Another workaround is to add a "not-prose" class to the map container:
While the above should reliably prevent any other Tailwind shenanigans, forcing the margin to be zero should work well enough for now. --- static/css/hugo-mod-leaflet.css | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/static/css/hugo-mod-leaflet.css b/static/css/hugo-mod-leaflet.css index cd92038..4a851e8 100644 --- a/static/css/hugo-mod-leaflet.css +++ b/static/css/hugo-mod-leaflet.css @@ -23,6 +23,13 @@ border-radius: 8px; } +/* Prevent styling from accidentally adding a margin to elements. Leaflet tiles are such + elements and adding a margin creates a hard-to-notice and hard-to-debug offset in map tiles. + This problem has been observed when embedding maps within a @tailwindcss/typography
. */ +.map-container img { + margin: 0px; +} + /* Heightgraph grid lines */ .map .heightgraph .grid .tick line { stroke: #ccc;