Anto Subash.

Published on

Css for leaflet div element

Css for the leaflet div

There are a few times when I set the div height to 100% the leaflet map is empty. This is mostly because the div is not fully occupying the entries space available. These are some CSS snippets I use during those times.

To fill the entire page

1#map {
2  height: 100vh;
3  width: 100vw;

To fill the entire div

1#map {
2  position: absolute;
3  top: 0;
4  bottom: 0;
5  left: 0;
6  right: 0;

Using CSS calc

Most of the times there will be a Top bar or a Sidebar available in the map during these times the calc function in the css will come in handy. lets assume you have side bar which is 100px and top bar which is 60px you can use something like below.

1#map {
2  width: calc(100vw - 100px);
3  height: calc(100vh - 60px);
4  margin-top: 60px;
5  margin-left: 100px;