谷歌地图div没有出现在JSBin中

如果我将宽度设置为500px,我可以在单击“开始”按钮时显示map-canvas div。 如果我将高度/宽度设置为100%,则不会显示。

我想确保我的项目会在移动设备上加载,所以我不想使用绝对尺寸。

使用可以使用没有width | height绝对定位 width | height值,使用top|left|bottom|right并将0设置为它们的值,这将导致#map-canvas div变为包含元素#second的大小,只要它被设置为相对像这样:

 #second { position: relative; } #map-canvas { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } 

这是更新的垃圾箱 。

我希望这有帮助!

请参阅Mike Williams对Google Maps Javascript API v2教程中百分比大小的解释

 html { height:100%; width: 100%; } body { padding-top: 50px; padding-bottom: 20px; height: 100%; width: 100%; } #map-canvas { height: 85%; width: 100%; }