Following the answer of @Ildar_Gabdullin , Iām using now as well two kinds of styleās references :
- Global : stored in my secrets.yaml
- Local : directly in a dashboard page with anchors
For my secrets.yaml file, I add name_of_my_css:
, followed by its style. Then, Iām able to call the style everywhere with this simple syntax:
style: !secret name_of_my_css
Here is an example of my secrets.yaml :
#-- *************************************************
#-- Inject custom CSS styles from Secret file
#-- *************************************************
gcss_graph_hacard: |
ha-card {
border: solid 2px rgb(64, 64, 64);
background-color: rgb(32, 32, 32);
border-radius: 25px;
}
Here is an example of my dashboard page that use secret references:
title: Home Info
path: home-info
icon: "mdi:home-heart"
badges: []
cards:
- type: entities
title: Temp (24h)
style: !secret gcss_graph_hacard
[...]
- type: vertical-stack
cards:
- type: "custom:mini-graph-card"
name: Co2
style: !secret gcss_graph_hacard
[...]
- type: vertical-stack
cards:
- type: "custom:mini-graph-card"
name: Noise
style: !secret gcss_graph_hacard
[...]
And when I need to use repetitive styles only on a single local page, for the first occurrence of style, I use an anchor style: &css_local_ha-card |
followed by its CSS code, then for the other instances with the same style, I only use the pointer style: *css_local_ha-card
Here is an example of the same dashboard page using anchor references
title: Home Info
path: home-info
icon: "mdi:home-heart"
badges: []
cards:
- type: entities
title: Temp (24h)
style: &mcss_graph_hacard |
ha-card {
border: solid 2px rgb(64, 64, 64);
background-color: rgb(32, 32, 32);
border-radius: 25px;
}
[...]
- type: vertical-stack
cards:
- type: "custom:mini-graph-card"
name: Co2
style: *mcss_graph_hacard
[...]
- type: vertical-stack
cards:
- type: "custom:mini-graph-card"
name: Noise
style: *mcss_graph_hacard
[...]
It helps me to reduce redundant code inside my dashboard views.