javascript - 谷歌地图后面的整页背景图像不会出现在 html 输出中

标签 javascript html css google-maps

我有一个加载谷歌地图的 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;
          }

最佳答案

嗯,

将 CSS 更改为以下对我有用:

body {
    background-image: url("images/myimage.jpg");
    background-size:cover;
    }  

 div#map-canvas
    {
     width:500px;
     height:250px;

     }

关于javascript - 谷歌地图后面的整页背景图像不会出现在 html 输出中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26671249/

相关文章:

javascript - 我在 javascript 函数上传递三个 3 参数,但它只得到第一个参数,这可能是错误的

javascript - 通过从范围内的 ng-repeat 获取动态 id 使用切换

javascript - 如何根据数据路径查找元素并更改其中的类

javascript - JavaScript 正则表达式中的惰性匹配前面部分

html - 多个 CSS 文件不起作用

javascript - 尝试创建一个小型网站,对 html 不熟悉。 div 有问题

javascript - jQuery - child 的麻烦

jquery - 悬停在顶层时如何展开所有菜单项,并在超出范围时再次删除它们?

jquery - 我通过 jquery 更改某些 css 样式后出现 iOS css 错误

html - 为什么 angular-datatable 不在 bootstrap 4 中填充 col?