开发者

Google Maps breaks with % instead of px dimensions

I'm making a page using the Google Maps API v3, similar to Google's example. I want the map to fill up the entire viewport, but when I set its width and height to 100%, it doesn't appear. Setting at least one dimension in px, though, makes it work. I'm using Firefox 3.5.6 and Internet Explorer 8. Now I want to get the page to work, but I'm also curious as to why on Earth this bug occurs.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<title>Map</title>
<style type="text/css">
html, body {
    margin: 0;
    padding: 0;
}
#map {
    width: 100%;
    /* Using % instead of px brea开发者_如何学Cks the map, I don't know why. */
    height: 500px;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
    var myLatLon = new google.maps.LatLng(36, -111);
    var myOptions = {
        zoom: 7,
        center: myLatLon,
        mapTypeId: google.maps.MapTypeId.TERRAIN
    }
    var map = new google.maps.Map(document.getElementById("map"), myOptions);
}
</script>
</head>
<body onload="initialize();">
<div id="map">Loading...</div>
</body>
</html>


Set the html, body styles too - use 100% height and width and 0 margin. Also add overflow:hidden to them (Think that fixes an IE bug).

Shameless plug: Checkout www.pinnspot.com ... I did that there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜