custom-cards / flex-table-card

Highly Flexible Lovelace Card - arbitrary contents/columns/rows, regex matched, perfect to show appdaemon created content and anything breaking out of the entity_id + attributes concept

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using variable in css

cfrets opened this issue · comments

I have a table with energy prices for each hour.

Hour | Price
00-01 | 0.12
01-02 | 0.34
...

I would like to change the background color on the row containing the price for the current hour.

When hardcoding the hour into the css selector, it works just fine, but when trying to use the current hour, it doesn't work.
How do I make it use a variable?

This work:
css: 'tbody tr:nth-child(18}) td': 'background-color: blue'

This doesn't work:
css: 'tbody tr:nth-child({{ new Date().getHours() }}) td': 'background-color: blue'
or
css: 'tbody tr:nth-child({% new Date().getHours() %}) td': 'background-color: blue'

Templates are not supported.
Use card-mod.

I fixed it with card_mod as suggested by @ildar170975
card_mod:
style: |
tbody tr:nth-child({{ now().hour }}) td {
background-color: blue;
}