Skip to content Skip to sidebar Skip to footer

Setting Google Maps Height To Image Height

On each page, I have a banner at the top. The banners are 1980px by 657px. HTML:

Solution 1:

You mean something like this?

Get width / height in jQuery. Apply it to the maps. Display: none on the image. A bit a dirty answer but it does the trick. I don't know how you would do it in pure css.

HTML

<divid="con"><imgid="img"src="http://dummyimage.com/600x200/000/fff.jpg" /><iframeid="maps"src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d76608.9275331472!2d23.1560658!3d53.127625249999994!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x471ffc048f41971d%3A0x72317dcc8bf07b2c!2sBia%C5%82ystok!5e0!3m2!1snl!2spl!4v1397752663976"></iframe></div>

CSS

#con {
  height: auto;
  width: auto;
  background-color: gray;
}

#img {
  display: none;
}

#maps {    
  margin: 0;
  padding: 0;
  display: block;
  border: none;
}

jQuery

var imgWidth = $('#img').width();
var imgHeight = $('#img').height();

$('#maps').width(imgWidth);
$('#maps').height(imgHeight);

Solution 2:

Why would you not just set the height of the #map div to auto, just as you do with your banner?

Is there some reason you could not do this?

Solution 3:

I am fairly certain that when you use tell Google Maps which div to append to, it removes all content from that div. In this case that probably includes your image.

Post a Comment for "Setting Google Maps Height To Image Height"