【发布时间】:2014-01-05 20:14:33
【问题描述】:
我正在尝试将 Google 地图放入 Bootstrap 内容选项卡 (this)。这是我的地图代码:
<style>
#map_canvas {
width: 500px;
height: 400px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var mapOptions = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, mapOptions);
};
google.maps.event.addDomListener(window, 'load', initialize);
</script>
这是我放置 map_canvas div 的地方:
<div class="tab-content">
...other divs here...
<div class='tab-pane fade' id='contact'>
<div class="row">
<div id="send_email" class='span4 pull-right'>
...blablabla a form here...
</div>
<div id="information" class='span8'>
<ul>...contact info...</ul>
<div id="map_canvas"></div>
</div>
</div>
</div>
这是 div 的代码:
$('#navtabs a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
真的,没什么特别的。然而由于某种原因,地图偏向一边,看起来像这样:
如果我尝试移动它,它只会自动将其自身固定在图片中的一半之外。省略 bootstrap.css 解决了这个问题。将#map_canvas 放在内容选项卡之外也可以解决问题。然而,我不能确切地说出是什么搞砸了。
这与最大宽度问题as suggested here 无关,因为我使用的引导程序是 2.3.2,它解决了它并默认包含这些行(将它们添加到我自己的 css 也无济于事) :
#map_canvas img,
.google-maps img {
max-width: none !important;
}
我尝试使用 chrome 开发工具并扫描 div 及其父对象,我检查了 bootstrap css 中的 .tab-content,我尝试省略 bootstrap.css 中的所有 img 属性,我尝试了 many @ SO的987654324@solutions,无济于事。
任何帮助将不胜感激。
【问题讨论】:
-
这篇文章可能会解决你的问题:stackoverflow.com/questions/20746698/…
-
拯救了我的一天。谢谢@MarcellinoBommezijn
标签: css google-maps twitter-bootstrap