I am working with creating a folium map within streamlit. I like the ControlLayer() functionality that folium provides, but I would like to be able to customize it a bit more. I found this comment that suggests appending css-classes to the folium default css list. I've tried overriding the classes that would effect the background color and label color, yet when I load the map, the default is still applied.
Would someone be able to explain what I am doing wrong? Could you please use my example to illustrate the correct way?
map_test.py
import folium import pandas import requests from streamlit_folium import folium_static state_geo = requests.get("https://raw.githubusercontent.com/python-visualization/folium-example-data/main/us_states.json").json() state_data = pandas.read_csv("https://raw.githubusercontent.com/python-visualization/folium-example-data/main/us_unemployment_oct_2012.csv") css_file = r"C:\Users\myname\leaflet_control_layer.css" css_classes = [ ('leaflet-control-layers', css_file), ('leaflet-control-layers-label', css_file) ] # Append each class to Folium's default CSS for label, css_file in css_classes: folium.folium._default_css.append((label, css_file)) m = folium.Map(location=[48, -102], zoom_start=3) folium.Choropleth( geo_data=state_geo, name="choropleth", data=state_data, columns=["State", "Unemployment"], key_on="feature.id", fill_color="YlGn", fill_opacity=0.7, line_opacity=0.2, legend_name="Unemployment Rate (%)", ).add_to(m) # Add layer control folium.LayerControl(collapsed=False).add_to(m) folium_static(m, width=800, height=800) leaflet_control_layer.css
/* Change the background color of the control layer */ .leaflet-control-layers { background-color: #4b00ad; /* Change this to your desired color */ } /* Change the text color of the control layer */ .leaflet-control-layers-label { color: #c70a9e; /* Change this to your desired color */ } 

