I created a custom template based on FastListTemplate and add my own ‘app.css’ file. In my app, I want to paint my button blue and the main content heading red. But since both panel components are in a shadow DOM, they are encapsulated by global styles. Hence, I use :host to find the shadow host with the class name and insert styles there.
Expected behavior: Heading should be in red and button should be blue
Actual behavior: Both components have default color from fast.css
Complete, minimal, self-contained example code that reproduces the issue :-
Put both files in the same directory and launch app.py
app.py
import panel as pn
import pathlib
from panel.template import FastListTemplate
class CustomTemplate(FastListTemplate):
_css = FastListTemplate._css + [pathlib.Path(__file__).parent / "app.css"]
def __init__(self, **params):
super().__init__(**params)
app = CustomTemplate()
app.main.append(pn.pane.Markdown("""# Color me red"""))
app.sidebar.append(pn.widgets.Button(name="Color me blue"))
app.servable()
app.css
:host(.solid) .bk-btn {
background-color: #23B7E5;
border: 1px solid #19A9D5;
color: white;
}
:host(.markdown) h1 {
color: red;
}