如何响应和集中谷歌地图

时间:2018-02-07 09:42:39

标签: javascript html google-maps

我正在尝试将大小为960x300的谷歌地图嵌入,并且始终是中心的标记点。这是我的代码。它是响应但不是正确的大小,当我最小化标记的地址不居中。我怎么能这样做?

<style>
    .google-maps {
        position: relative;
        padding-bottom: 75%; 
        height: 0;
        overflow: hidden;
    }
    .google-maps iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
    }
    .gbox{
        width:960px;
        height:300px;

    }
</style>
<!DOCTYPE html>
<html>

<body>

    <h1>My Map</h1>
    <p>My first paragraph.</p>
    <div class="google-maps">
    <div class="gbox">

        <iframe src="https://www.google.com/maps/d/embed?mid=1XgV0prYhOa2ojHCt-7VcYbLaXnzIICKP" width="640" height="480"></iframe></div></div>
</body>

</html>

1 个答案:

答案 0 :(得分:0)

请更新此代码

.gbox{
        width:960px;
        height:300px;
        margin: auto;
        text-align: center;
    }
    iframe{
        width: 100%;
    }
    @media(max-width:991px){  
        .gbox{
            width:100% !important;
            height:auto;
        }
        .google-maps {
            position: relative;
            padding-bottom: 75%; 
            height: 0;
            overflow: hidden;
        }
        .google-maps iframe {
            position: absolute;
            top: 0;
            left: 0;
            width: 100% !important;
            height: 100% !important;
        }
    }