Does anyone have an idea how to center numbers inside markers? This is the current situation.
Creating a Marker
return L.divIcon({
className: "green-icon",
iconSize: [25, 41],
iconAnchor: [10, 44],
popupAnchor: [3, -40],
html: markerNumber,
});
CSS
.green-icon {
background-image: url("../GreenIcon.png");
background-repeat: no-repeat;
margin: 0 auto;
text-align: center;
color: white;
font-weight: bold;
}
This should work.
return L.divIcon({
className: "green-icon",
iconSize: [25, 41],
iconAnchor: [10, 44],
popupAnchor: [3, -40],
html: `<span class="icon-text">${markerNumber}</span>`
})
Add this to your CSS.
.icon-text {
text-align: center;
}
.green-icon {
display: grid;
align-items: center;
}
JSfiddle example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.