This seems to be possible just in CSS. Below I'm overriding (with !important
) just three CSS elements, and adding one :before
pseudo-element. I'm essentially first lining up the popup with the top instead of bottom, where 55px
just depends on your chosen marker, and personal taste.
I then move the popup's "tip" similarly from bottom to top:0px
, and discover it's not made using the "normal" trick (that is: first position on the bubble's edge a 0x0-sized pseudo-element with a thick transparent border, then colour that element's opposite border of where you want to point; in our case, the bottom-border). Instead it seems to be made from a rectangle rotated in from somewhere top-left (maybe: because it forces the browser to use the GPU and hence accelerates everything?) and I don't get the point (pardon the pun) well enough (my tip is in the right place but invisible); so I just remove the box-shadow that's now in the wrong place and leave it all as-is --- anyone who understands the "old tip" please adjust that.
So instead I make my own tip, with the "normal" process (if you're unsure, change the four border colours below, instead of 3x transparent and 1x white --- e.g. border-bottom-color: blue; border-left-color: green; border-top-color: yellow' border-right-color: red
).
#map {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
z-index: 0;
}
.leaflet-popup {top: 55px !important;}
/* Here I move the "tip" to the right location, but didn't succeed in making it visible. So I just remove the box-shadow and leave it: */
.leaflet-popup-tip-container {
top: 0px !important;
}
.leaflet-popup-tip {
box-shadow: none !important;
}
.leaflet-popup:before
{
content: "";
position: absolute;
border: 13px solid transparent;
border-bottom-color: white;
bottom: 0px;
margin-left: -13px;
}
As this JSFiddle demonstrates, no problem with different popup-sizes (different width, different textheight) if you try both markers.
All in all this seems robust against updates in Leaflet as the items I'm overriding don't seem likely to change.