-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a parameter to Popup that allows users to add CSS classes #2848
Comments
This functionality is not currently supported in GL JS. I have repurposed this ticket to track that functionality. I encourage you to submit a PR adding it! Here is the relevant line: http://github.com/mapbox/mapbox-gl-js/blob/66a567cfb7b566f672f7e77399c6607ad86701ce/js/ui/popup.js#L174-L175 |
Instead of adding a class to the |
please refer to mapbox#2848 (comment)
I down voted this because it is a child of the popup container which includes the popup tip, hence with this approach it seems you can't control the style of the popup tip. Adding CSS classes to the root popup container would address that. |
Here my "brute-force" solution for changing background of popup belonging to marker. Double use of parentNode to access main element, append className and create appropriate styles for tip. In the same manner u can play with border length to change tip length or override any styles u need without replacing default Mapbox styles. var popup = new mapboxgl.Popup();
var content = document.createElement('div');
content.innerHTML = '<p>some html</p>';
popup.setLngLat([-118.705, 34.142])
.addTo(map)
.setDOMContent(content);
content.parentNode.parentNode.className += ' mapboxgl-popup--blue';' Then you can write CSS: .mapboxgl-popup.mapboxgl-popup--blue {
/*any styles u wish*/
}
.mapboxgl-popup--blue .mapboxgl-popup-content{
background-color: rgb(66,111,175);
padding:20px;
color: white;
max-width:none;
}
.mapboxgl-popup--blue.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip{
border-top-color: rgb(66,111,175);
}
.mapboxgl-popup--blue.mapboxgl-popup-anchor-top .mapboxgl-popup-tip{
border-bottom-color: rgb(66,111,175);
}
.mapboxgl-popup--blue.mapboxgl-popup-anchor-left .mapboxgl-popup-tip{
border-right-color: rgb(66,111,175);
}
.mapboxgl-popup--blue.mapboxgl-popup-anchor-right .mapboxgl-popup-tip{
border-left-color: rgb(66,111,175);
}
.mapboxgl-popup--blue.mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip{
border-bottom-color: rgb(66,111,175);
}
.mapboxgl-popup--blue.mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip{
border-bottom-color: rgb(66,111,175);
}
.mapboxgl-popup--blue.mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip{
border-top-color: rgb(66,111,175);
}
.mapboxgl-popup--blue.mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip{
border-top-color: rgb(66,111,175);
} |
how do I append a class along with class
mapboxgl-popup
. ThanksThe text was updated successfully, but these errors were encountered: