Google地图CSS不显示地图 [英] Google Maps CSS don't show map
问题描述
我在将Google地图添加到我的项目时遇到了一些问题。当我得到它的身体标签它工作。但是当我有这样的结构
I have some problem with adding Google Maps to my project. When i get it into body tags it works. But when I have structure like this
<body onload="initialize()">
<div>
<div id="map_canvas" style="width:100%; height:100%"></div>
</div>
</body>
它不显示任何内容。如何解决这个问题?
it doesn't show anything. How I can solve this problem?
推荐答案
这是因为 height:100%;
是始终相对于父级的高度。在你的情况下,这是无名的div,它的高度为零,因此 #map_canvas
将是它的100%,它仍然为零。因此,Google地图不会显示,因为div没有可见的高度。
It is because height: 100%;
is always relative to the parent's height. In your case, this is the nameless div, which has zero height, so #map_canvas
will be the 100% of that, which is still zero. So the Google Maps won't show because the div has no visible height.
如果您指定100%的父div,它将再次工作。我猜你已经有 html,body {height:100%;
If you specifiy 100% on the parent div, it will work again. I guess you already have html, body { height: 100%; }
if it works being simply in the body tag.
这篇关于Google地图CSS不显示地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!