我希望将标签的高度和宽度设置为 100%,现在在其他示例中它可以使用下面演示的标签。但是在下面给出的代码中,如果我删除了 "style="width: 370px; height: 505px""来自 并在 meta 标记后添加以下代码
<style type="text/css>
body{
height:100%;
width:100%;
}
#map-canvas{
height:100%;
width:100%;
}
</style>
它不起作用。
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"> </script>
<script type="text/javascript">
var shape;
function initialize() {
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(24.886436490787712, -70.2685546875),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
shape = new google.maps.Polygon({
strokeColor: '#ff0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#ff0000',
fillOpacity: 0.35
});
shape.setMap(map);
google.maps.event.addListener(map, 'click', addPoint);
}
function addPoint(e) {
var vertices = shape.getPath();
vertices.push(e.latLng);
}
function clearmap(){
initialize();
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body style="font-family: Arial; border: 0 none;">
<div id="map-canvas" style="width: 370px; height: 505px"></div>
<input type="button" value="click" onclick="clearmap"()>
</body>
最佳答案
我用你的代码做了一个 jsfiddle
...以及 Rohit Azad 的回答,将 html
标记添加到文档样式,似乎可以解决您的问题(至少在 jsfiddle 上)。
关于android - 如果在 "%"中设置,CSS 将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16436215/