Google地图CSS不显示地图

编程入门 行业动态 更新时间:2024-10-25 14:23:01
本文介绍了Google地图CSS不显示地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在将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.

jsFiddle Demo

更多推荐

Google地图CSS不显示地图

本文发布于:2023-06-07 22:04:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地图   Google   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!