中心谷歌地图vue组件

用户1592380

在此处输入图片说明

我有一个 vue/nuxt 谷歌地图组件,看起来像:

<template>
  <GmapMap
  :center="{lat:10, lng:10}"
  :zoom="7"
  map-type-id="terrain"
  style="width: 500px; height: 300px"
>
  <!-- <GmapMarker
    :key="index"
    v-for="(m, index) in markers"
    :position="m.position"
    :clickable="true"
    :draggable="true"
    @click="center=m.position"
  /> -->
</GmapMap>

</template>


<script>


export default {
  // name:'myMap'

}

</script>


<style>
  margin: 0 auto;
  width: 50%;;

</style>

地图未居中(请参见屏幕截图)。我怎样才能把它居中?

margin: 0 auto 居中技术仅适用于块级元素。

所以给你的组件 display: block;

div, span {
  margin: 0 auto; 
  width: 200px; 
  border: 1px solid red;
}
<div>working</div>
<span>not working</span>
<span style="display:block">working</span>

或者,您可以简单地将它包装在一个元素中:

  • text-align: center;
  • 或者 display: flex; justify-content: center;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章