我有一个加载谷歌地图的html页面。我想使用图像作为背景来覆盖整个HTML页面。但由于某种原因,背景图像不会出现,但谷歌地图会加载到指定的div中。我的文件正在关注(markerdrop.html):
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<link rel="stylesheet" type="text/css" href="markerdropstyle.css" />
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!'
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
和markerdroptsyle.css:
html{
/* This image will be displayed fullscreen */
background:url("images/myimage.jpg") no-repeat center center;
/* Ensure the html element always takes up the full height of the browser window */
min-height:100%;
/* The Magic */
background-size:cover;
}
body{
/* Workaround for some mobile browsers */
background:url("images/myimage.jpg") no-repeat center center;
/* Ensure the html element always takes up the full height of the browser window */
min-height:100%;
/* The Magic */
background-size:cover;
min-height:100%;
}
#map-canvas {
height: 500px;
width: 500px;
}
答案 0 :(得分:0)
好吧,
将CSS更改为以下内容对我有用:
body {
background-image: url("images/myimage.jpg");
background-size:cover;
}
div#map-canvas
{
width:500px;
height:250px;
}