Set Google Maps Container DIV width and height 100%

后端 未结 12 964
遇见更好的自我
遇见更好的自我 2020-11-28 04:45

I loaded Google Maps API v3 and print Google Map in div. But when set width & height to 100% and auto I can\'t see the Map.

Here is HTML code snippe

12条回答
  •  醉酒成梦
    2020-11-28 05:41

    Very few people realize the power of css positioning. To set the map to occupy 100% height of it's parent container do following:

    #map_canvas_container {position: relative;}

    #map_canvas {position: absolute; top: 0; right: 0; bottom: 0; left: 0;}

    If you have any non absolutely positioned elements inside #map_canvas_container they will set the height of it and the map will take the exact available space.

提交回复
热议问题