2010-07-12 156 views
3

我只是需要把一個DIV(或更多)中或上的地圖,像地圖區域內的菜單DIV,谷歌地圖V2內或在地圖

我需要當我加載我的地​​圖這個div是存在的...

css不能做到這樣對不對?

該div包含PHP代碼...

+0

你想對你的菜單股利消失,一旦地圖推出?還是你想讓它在地圖上浮動? – 2010-07-12 00:12:06

+0

我需要div浮動, 謝謝 – TiagoMartins 2010-07-12 00:17:10

回答

3

是的,這很容易與CSS定位來完成。考慮下面的簡單的例子:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps v2 API: Floating Div</title> 
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false" 
      type="text/javascript"></script> 
</head> 
<body onunload="GUnload()"> 

    <div style="position: relative;"> 
    <div id="map_canvas" style="width: 400px; height: 300px;"></div> 
    <div style="position: absolute; top: 0px; 
       width: 100px; height: 100px; background-color: grey;"> 
     Menu Here 
    </div> 
    </div> 

    <script type="text/javascript"> 
    var map = new GMap2(document.getElementById("map_canvas")); 
    map.setCenter(new GLatLng(38.00, -100.00), 3); 
    </script> 
</body> 
</html> 

截圖:

Google Maps v2 API: Floating Div

+0

謝謝,它非常適合我! – TiagoMartins 2010-07-12 00:50:43

0

這爲我工作的谷歌地圖API3。

其中我的菜單下拉元素現在以正確的順序覆蓋Google Maps API3。

這是重要的CSS代碼:

.menudropdown { 
    position: fixed; 
    z-index:2; 
} 

#map { 
    position: absolute; 
    z-index:1; 
}