A couple of ideas but please note that I am by no means an expert in CSS. But it seems that in Bokeh version 3 the change to shadow DOM elements breaks ones old setup. Now it seems you can use stylesheets go style the bk-btn within a shadow DOM. In the example below I use
style_btn2 = """.bk-btn {
font-family: Arial;
font-size: 20px;
color: red;
border-color: red;
background-color: grey;
}"""
and add that to stylesheets as a list.
If you want to use an external css file it becomes complex. One needs to select the shadowRoot of the element and the style sheet to that. That is in the JS function in the code below.
from bokeh.io import save
from bokeh.models import Button
from bokeh.plotting import figure
style_btn2 = """.bk-btn {
font-family: Arial;
font-size: 20px;
color: red;
border-color: red;
background-color: grey;
}"""
btn1 = Button(label = "Button 1", name = "btn1")
btn2 = Button(label = "Button 2", stylesheets = [style_btn2], name = "btn2")
btn3 = Button(label = "Button 3", name = "btn3", classes = ["btn3"])
template = """
{% block preamble %}
<link href="styles.css" rel="stylesheet">
{% endblock %}
{% block contents %}
<div class="container">
<div class="row">
<div class="btn-div">
Default <code>bk-btn</code>
<div class="bk-wdg-center">
{{ embed(roots.btn1) }}
</div>
</div>
<div class="btn-div">
Using <code>stylesheets</code>
<div class="bk-wdg-center">
{{ embed(roots.btn2) }}
</div>
</div>
<div class="btn-div">
JS function to select <code>shadowRoot</code><br>
and add external stylesheet.
<div class="bk-wdg-center">
{{ embed(roots.btn3) }}
</div>
</div>
</div>
</div>
</div>
<script>
function runBkScript() {
if ((window.Bokeh.documents[0] !== undefined)) {
let sroot = document.getElementsByClassName("btn3")[0].shadowRoot;
const linkElem = document.createElement("link");
linkElem.setAttribute("rel", "stylesheet");
linkElem.setAttribute("href", "styles.css");
// Attach the created element to the shadow DOM
sroot.appendChild(linkElem);
} else {
setTimeout(runBkScript, 1000);
}
}
window.onload = function() {
runBkScript();
}
</script>
{% endblock %}
"""
contents = [btn1, btn2, btn3]
save(contents, template=template, title="CSS button")
styles.css
.bk-btn {
font-family: Arial;
font-size: 15px;
color: white;
border-color: yellow;
background-color: black;
}
.container {
/*max-width: 1500px;*/
margin: auto;
}
.row {
display: flex;
justify-content: center;
}
.btn-div {
margin: 10px;
}
.bk-wdg-center {
display: flex;
justify-content: center;
}