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?

1

11 Answers 11

186

With Bootstrap 2.0, this seemed to do the trick:

#mapCanvas img { max-width: none; } 
Sign up to request clarification or add additional context in comments.

8 Comments

Make sure to add #mapCanvas img { width: auto; display:inline; } as mentioned below by @nodrog
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."
FYI: Bootstrap 2.0.4 release notes: "Added special CSS to prevent max-width: 100%; on images from messing up Google Maps rendering."
That's strange that they have finally decided to hardcode id, not use class instead
#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!
|
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.

3 Comments

Yes ! everything seems fixed with this one combined with the answer flagged as "accepted" above. Thanks.
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'); });
You are a genius. Thanks very much. This was driving me insane :-)
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).

4 Comments

I think only to change the id is necessary in v2.2.2
i cannot find such id in css file
@robd : Just for curious, Why it will not work for except map_canvas.
@ArunRaj because the fix in bootstrap is hardcoded to the #map_canvas id (see the linked commit). In any case, this answer is probably out of date now given that it's nearly 2 years old.
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.

3 Comments

+1 this is the only answer that worked for me to fix the weird "zoom" controls. (Bootstrap 2)
Worked for me too. Good spotting :)
Thanks, worked for me too. The only answer that worked for me to fix the weird "zoom" controls. (with Foundation 5)
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

Comments

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; } 

Comments

2

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

.gmaps4rails_map img { max-width: none; } .gmaps4rails_map label { width: auto; display:inline; } 

Comments

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%"

Comments

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; } } 

Comments

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; } 

1 Comment

This worked for me. If you're gonna vote someone down, you should at least say why.
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 { }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.