gpt4 book ai didi

javascript - 如何将 css 添加到传单按钮?

转载 作者:行者123 更新时间:2023-11-30 14:19:29 25 4
gpt4 key购买 nike

我正在尝试更改传单中缩放按钮的 CSS,但我无法向这些按钮添加类或 ID 或任何内容。我怎样才能访问它们?

有什么想法吗?

谢谢!

我在这里声明 map :

L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoicHcxN2wwMDgiLCJhIjoiY2pua2c2OWxuMGVkOTNxbWh5MWNqajEwdyJ9.X_SuGwNGs12TwCsrsUvBxw'
}).addTo(map);

这里我包括缩放:

L.control.zoom({
position: 'topright',
}).addTo(map);

当页面加载时,我看到它变成了一个带有许多传单类的按钮,但我该如何对它们进行更改?

最佳答案

我想还有其他方法,但为了更改缩放按钮的样式,您可以访问内置的 css 选择器,如下所示:

.leaflet-touch .leaflet-bar a {
width: 50px;
background-color: red;
}

var map = L.map('mapid').setView([51.505, -0.09], 13);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

L.marker([51.5, -0.09]).addTo(map)
.bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
.openPopup();
#mapid {
height: 180px;
}

.leaflet-touch .leaflet-bar a {
width: 50px;
background-color: red;
}

body {
margin: 0px;
}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js" integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg==" crossorigin=""></script>

<div id="mapid"></div>

或使用 js:

document.getElementsByClassName("leaflet-control-zoom-out")[0].style.setProperty('width', '50px');

document.getElementsByClassName("leaflet-control-zoom-out")[0].style.setProperty('background-color', 'red');

关于javascript - 如何将 css 添加到传单按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52995641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com