Responsive iframe (google maps) and weird resizing

后端 未结 1 1526
忘了有多久
忘了有多久 2020-12-07 10:09

I am trying to add a Google Map to my design, that is supposed to be responsive. I\'ve used the same code that works out for images... But for some reason, the map\'s iframe

相关标签:
1条回答
  • 2020-12-07 10:40

    This solution is from Dave Rupert / Chris Coyier (I think). It requires a wrapper div but works pretty well.

    HTML

        <div class="iframe-rwd">
            <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Seattle,+WA&amp;aq=0&amp;oq=seattle&amp;sll=37.822293,-85.76824&amp;sspn=6.628688,16.907959&amp;t=h&amp;ie=UTF8&amp;hq=&amp;hnear=Seattle,+King,+Washington&amp;z=11&amp;ll=47.60621,-122.332071&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=Seattle,+WA&amp;aq=0&amp;oq=seattle&amp;sll=37.822293,-85.76824&amp;sspn=6.628688,16.907959&amp;t=h&amp;ie=UTF8&amp;hq=&amp;hnear=Seattle,+King,+Washington&amp;z=11&amp;ll=47.60621,-122.332071" style="color:#0000FF;text-align:left">View Larger Map</a></small>
        </div>
    

    CSS

    .iframe-rwd  {
    position: relative;
    padding-bottom: 65.25%;
    padding-top: 30px;
    height: 0;
    overflow: hidden;
    }
    .iframe-rwd iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    }
    
    0 讨论(0)
提交回复
热议问题