简体   繁体   English

如何让传单地图画布具有 100% 的高度?

[英]How to get a leaflet map canvas to have a 100% height?

My leaflet canvas currently looks like the following, with a 700px height:我的传单画布目前如下所示,高度为 700 像素:

高度为 700 像素的地图

However I would like its height it be 100%, in order to take the whole white space.但是我希望它的高度是 100%,以便占据整个空白区域。

height:100% doesn't work in the CSS properties of the map canvas. height:100%在地图画布的 CSS 属性中不起作用。 I found a few solutions but they are only good for Google Maps.我找到了一些解决方案,但它们只适用于谷歌地图。

Does anybody has a solution, even if it's only a workaround ?有没有人有解决方案,即使它只是一种解决方法? Thanks !谢谢 !

The best way is to use the CSS length units vh and vw .最好的方法是使用 CSS 长度单位vhvw These allow a block-level HTML element to have a dimension relative to the viewport size, instead of the size of its parent element (as % does).这些允许块级 HTML 元素具有相对于视口大小的维度,而不是其父元素的大小(如%所做的那样)。

eg:例如:

#map {
  width: 100vw;
  height: 100vh;
}

For reference: https://developer.mozilla.org/en-US/docs/Web/CSS/length供参考: https ://developer.mozilla.org/en-US/docs/Web/CSS/length

Using height: 100% does work, it only needs the parent containers to have a size too ( working demo ):使用height: 100%确实有效,它只需要父容器也有大小(工作演示):

html, body { 
    height: 100%; 
}
#map {
  width: 100%;
  height: 100%;
}

Just as an alternative approach: If you have a fixed height nav bar at the top, say 50px, and fixed width on the left, say 100px, then you can make the map take up the rest of the space like this:就像另一种方法一样:如果您在顶部有一个固定高度的导航栏,比如 50 像素,左侧是固定宽度,比如 100 像素,那么您可以让地图占据其余空间,如下所示:

#map {
    position: absolute;
    top: 50px;
    right: 0;
    bottom: 0;
    left: 100px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM