首页 > 解决方案 > Leaflet Easy Button中图标的位置

问题描述

我在传单地图上使用传单简易按钮:

<!-- Load LeafletEasyButton -->  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet-easybutton@2/src/easy-button.css">
<script src="https://cdn.jsdelivr.net/npm/leaflet-easybutton@2/src/easy-button.js"></script>

我也在使用 Google Material 图标:

<!-- Load Google Material Icons -->
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

目标是在我的传单地图上创建一个自定义按钮,如下所示:

L.easyButton('<i class="material-icons" style="font-size:18px;">gps_fixed</i>', function(){
    locateMe();
}, {position: 'bottomright'}).addTo(map);

它可以工作,但我的自定义按钮中的图标位于按钮中心上方:

在此处输入图像描述

如何使图标居中?

标签: javascriptcssleafletgoogle-material-icons

解决方案


您可以在 CSS 代码中使用左/上:

 .widget-code {
    display: block;
    height: 18px;
    left: 6px;
    margin: 0;
    padding: 0;
    position: absolute;
    top: 6px;
    width: 18px;
}

推荐阅读