147

I'm using Twitter Bootstrap, and have a Google map.

Images on the map, such as marker are being skewed by the CSS in Bootstrap.

In the Bootstrap CSS there is:

img {
    border: 0 none;
    height: auto;
    max-width: 100%;
}

When I disable the max-width property using Firebug, the marker image appears as normal. How can I prevent the Bootstrap CSS from affecting the Google maps images?

Ryan
  • 2,948
  • 3
  • 30
  • 41
raklos
  • 28,027
  • 60
  • 183
  • 301

11 Answers11

186

With Bootstrap 2.0, this seemed to do the trick:

#mapCanvas img {
  max-width: none;
}
kevinwmerritt
  • 2,218
  • 1
  • 15
  • 12
  • 6
    Make sure to add `#mapCanvas img { width: auto; display:inline; }` as mentioned below by @nodrog – jlb Mar 09 '12 at 18:58
  • From Bootstrap 2.0.3 release notes: "Fixed regression in responsive images support as of 2.0.1. We've re-added max-width: 100%; to images by default. We removed it in our last release since we had folks complaining about Google Maps integration and other projects, but we're taking a different stance now on these things and will require developers to make these tweaks on their end." – kevinwmerritt Apr 30 '12 at 16:58
  • FYI: Bootstrap 2.0.4 release notes: "Added special CSS to prevent max-width: 100%; on images from messing up Google Maps rendering." – kevinwmerritt Jul 31 '12 at 16:56
  • That's strange that they have finally decided to hardcode id, not use class instead – zerkms Aug 10 '12 at 11:36
  • 1
    #mapCanvas didn't work for me. I just used my .map class that i used as the google maps container and it did the trick. THANKS! – Fydo Oct 27 '12 at 02:06
  • didn't work for us using gmap4rails gem, but did when we changed to .map_container img { max-width: none; } .map_container label { width: auto; display:inline; } – Sam Joseph May 17 '13 at 10:22
  • Awesome man.. For 2 projs i thought there was something wrong with google maps///:) – phpdev Oct 29 '13 at 04:24
  • Essentially this also works for Gmaps4rails and Zurb Foundation: Use `img { max-width: none; width: auto; display: inline; }` on .smap (the class name can be choosen via gmaps()' map_options) – Yo Ludke Jun 03 '14 at 08:18
80

There is also an issue with the dropdown selectors for terrain and overlays, adding both these will fix the issues...

#mapCanvas img { 
  max-width: none;
}

#mapCanvas label { 
  width: auto; display:inline; 
} 

The second style will sort of other issues with the terrain and overlay box in some browsers.

nodrog
  • 3,532
  • 2
  • 25
  • 31
  • Yes ! everything seems fixed with this one combined with the answer flagged as "accepted" above. Thanks. – Mat May 19 '12 at 20:37
  • works like a charm in firefox 17 but not in chrome 23. dont know why but i found the solution just add this: `$('.map').on('shown',function(){ google.maps.event.trigger(map, 'resize'); });` – yosafatade Dec 09 '12 at 19:12
  • You are a genius. Thanks very much. This was driving me insane :-) – Bear Aug 21 '13 at 14:19
20

Give your map canvas div an id of map_canvas.

This bootstrap commit includes the max-width: none fix for the id map_canvas (but it won't work for mapCanvas).

robd
  • 9,646
  • 5
  • 40
  • 59
11

None of these answers worked for me, so I went in to my div and looked at its children I saw a new div with class "gm-style", so I put this in my CSS:

.gm-style img {
    max-width: none;
  }

  .gm-style label {
    width: auto; display:inline;
  }

..and that solved the problem for me.

Christopher Dow
  • 325
  • 4
  • 9
3

You want to over-ride the max-width rule in the CSS section by using max-width: none; This seems to be the way around this problem

Pawpoint
  • 31
  • 2
2

Changing the #MapCanvas didn't work for us using gmap4rails gem, but did when we changed to

.map_container img {
    max-width: none;
}

.map_container label {
    width: auto; display:inline;
}
Sam Joseph
  • 4,584
  • 4
  • 31
  • 47
2

I am using gmaps4rails, this fix did it for me:

.gmaps4rails_map img {
    max-width: none;
}
.gmaps4rails_map label {
    width: auto; display:inline;
}
Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236
1

latest twitter bootstrap 2.0.4 includes this fix directly.

If you are wrapping your content in the a (div class="container") as in the demo page of twitter bootstrap, you should add a style="height: 100%"

redochka
  • 12,345
  • 14
  • 66
  • 79
1

There is also an issue with printing maps using Print in any browser. The img { max-width: 100% !important; } will not be fixed by the code above: you need to add an !important declaration like so:

@media print {
  img {
    max-width: auto !important;
  }
}
tempranova
  • 929
  • 9
  • 13
0

I also had to turn box-shadow off, and because of the order of my includes, I added the !important flag.

#mapCanvas img {
    max-width: none !important;
    box-shadow: none !important;
}
Redtopia
  • 4,947
  • 7
  • 45
  • 68
0

All answers were max-widht:none

for me, max-height:inherit worked.....

People are using #map, #map_canvas, etc. Look at your parent div. If it's blue, than it will be #blue img { }

user2060451
  • 2,576
  • 3
  • 24
  • 31