html - 在谷歌地图下定位内容

标签 html css google-maps

我有一张谷歌地图,上面有一 block 内容在 laiyng 上,这正是我所需要的。

我需要能够在谷歌地图下方添加更多内容..但我无法弄清楚如何让正在进行的 div 容器位于 map 下方。

我试过将位置设置为静态,但它不起作用?

下面是我的代码笔:-

http://codepen.io/dyk3r5/pen/LRmWbq

HTML。

<div id="content">

  <iframe id="gmap" width="600" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/?ie=UTF8&amp;ll=55.886721,-4.33651&amp;spn=0.011553,0.027466&amp;z=15&amp;output=embed"></iframe>
  <div class="container overlap">
    <h1>Content</h1>

  </div>
</div>

<div class="moreContent">

  <p>I would like to sit below the google map!</p>

<div>

CSS。

#gmap {
  position:absolute;top:0;left:0;z-index:1;
}
.overlap{
  position: relative;
  z-index:2;
  background: white;
  height : 200px;
  width : 200px;
  margin-top: 100px;
}

.moreContent{
  /* How doi position this container? */
}

最佳答案

你可以这样做

.moreContent{
    position:absolute; 
    top:450px
} 

但更好的解决方案是不在 #gmap 元素上使用 position:absolute;

此外,您正在使用 iframe 将 map 嵌入到您的页面中,更好的解决方案是为此使用 Google Maps JavaScript API。

这是我将如何做到的:

#map{
  width: 600px;
  height: 450px;
}

.overlap{
  position:absolute;
  top:100px;
  z-index:2;
  background: white;
  height : 200px;
  width : 200px;
}
<!DOCTYPE html>
<html>
  <body>
    <div id="map"></div>
    
    <div class="container overlap">
       <h1>Content</h1>
    </div>
    <div class="moreContent">
        <p>I would like to sit below the google map!</p>
    <div>
    
    
    <script>
      var map;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: 55.886721, lng:-4.33651},
          zoom: 15
        });
      }
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
    async defer></script>
  </body>
</html>

如果您使用的是 Google Maps JavaScript API,则可以通过创建自定义控件在 map 上添加元素,您可以在此处找到更多相关信息:https://developers.google.com/maps/documentation/javascript/controls#CustomControls

关于html - 在谷歌地图下定位内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39974743/

相关文章:

java - 如何在 observable 上编写我自己的操作以将所有内容映射到常量?

javascript - 如何检查给定标记是否在区域内

JavaScript输入格式DD :HH

html - 沿顶部对齐单元格中的标签(valign 和 vertical-align 不起作用)

html - 视口(viewport)边框

html - 如何在 HTML 中包装一行列表项

html - 嵌套 Sass 访问

javascript - 如何捕捉 div 位置并稍后重新定位(在 MAC 上)

html - z-index IE7, IE8, IE9 不起作用?

python - 按接近度对一组点进行分组