Set Google Maps Container DIV width and height 100%

后端 未结 12 903
遇见更好的自我
遇见更好的自我 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:35

    Better late than never! I made mine a class:

    .map
    {
        position:absolute;
        top:64px;
        width:1100px;
        height:735px;
        overflow:hidden;
        border:1px solid rgb(211,211,211);
        border-radius:3px;
    }
    

    and then

    <div id="map" class="map"></div>
    
    0 讨论(0)
  • You can set height to -webkit-fill-available

    <!-- Maps Container -->
    <div id="map_canvas" style="height:-webkit-fill-available;width:100px;"></div>
    
    0 讨论(0)
  • 2020-11-28 05:38

    Gmap writes inline style position to relative to the div. Overwrite that with :

    google.maps.event.addListener(map, 'tilesloaded', function(){
        document.getElementById('maps').style.position = 'static';
        document.getElementById('maps').style.background = 'none';
    });
    

    Hope it helps.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-28 05:42

    If you can't affect your parents elements (like in a nested components situation) you can use height: 100vh which will make it a full window (=view) height;

    0 讨论(0)
  • 2020-11-28 05:42

    This worked for me.

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

    0 讨论(0)
提交回复
热议问题