šŸ”¹ Card-mod - Add css styles to any lovelace card

First, (and may be I am wrong) check if the Grid card has a ha-card element (in Code Inspector).
If not - use mod-card.

This is what it is in Code Inspector

This mod-card it is a specific lovelace card? I should install it from hacs or something?

Edit: I see there is a ha-card element but not of the grid card.
About the mod-card, now I found out what is this :slight_smile: my badā€¦ But how can I achieve what I want? :frowning:

This is what I triedā€¦ no luck :frowning:

card_mod:
  style:
    hui-grid-card$:
      '#root': 
        hui-button-card$: |
          ha-card{
            background: red !important;}
          }

Iā€™m trying to change the color of a ha-svg-icon to solve the problem. However, no matter what I specify, nothing is changed.

Issue

Selector

    card_mod:
      style: |
        ha-svg-icon {
          color: red;
        }

Hey guys, how can I change the color in this glance card ONLY for the state and not for the Entity-Name above.

As often: First Post ā†’ Link to examples from ildar at the bottom ā†’ Glance card

Does this still work? I cant seem to get mine to change size

Wondering if anyone had some advice for my post here. Really scratching my head on this one.

All of the styling on this 2nd screenshot is exactly the same as my original post (I have added one entity marked by the light bulb mdi). Iā€™m finding when I restart home assistant, the card uses the red color I have defined when cycling sensors and entities on the card.

It only does this on restart. As soon as Home Assistant has fully restarted, it reverts to the default yellow.

Does anyone have any good resources to learn CSS styles/CardMod in general?

image

First Post ā†’ Link from Ildar. And card_mod-github site with examples and explanations as well.

What happens if you open the browser dev tools and disable the cache?

You might be suffering of this:

NOTE 2: Following on the note above; due to the high level of load order optimization used in Home Assistant, it is not guaranteed that the #shadow-root or the mwc-buttonactually exists at the point in time when card-mod is looking for it. If you use the second method above, card-mod will be able to retry looking for #shadow-root at a later point, which may lead to more stable operation.

In short; if things seem to be working intermittently - try splitting up the chain.

You would make a life easier for people if you attach a screenshot with a DEFAULT theme, otherwise it looks really weird.

Have a website card like this:

type: iframe
url: /local/Schultermine.html
title: 'Termine'
aspect_ratio: 100%
card_mod:
  style: |
    ha-card { 
      background: transparent !important; 
    }       
    .card-header {
      justify-content: center !important;
    }

But I canĀ“t get the iframe background transparent or the title of this HA website Card to be centered.
Background is displayed white and Title is shown left

Can anybody help?

What about links?

<a href="whatever">whatever</a>

Like, I donā€™t want the link to be underlined and blueā€¦

Hey there!
I tried many approaches to reach the code below as clean as possible, but this was the best that I could. Do you guys can tell me how do do it better ?

state_color: false
type: glance
entities:
  - entity: sensor.sm_g780g_battery_level
    name: S20
    card_mod:
      style: |
        state-badge {
          {% if states(config.entity)|float >= 70 %}
            color: #4caf50;
          {% elif states(config.entity)|float >= 15 %}
            color: #ff9800;
          {% else %}
            color: #f44336;
          {% endif %}
        }
  - entity: sensor.s22_battery_level
    name: S22
    card_mod:
      style: |
        state-badge {
          {% if states(config.entity)|float >= 70 %}
            color: #4caf50;
          {% elif states(config.entity)|float >= 15 %}
            color: #ff9800;
          {% else %}
            color: #f44336;
          {% endif %}
        }

The goal is just to change battery bounds to 15% instead of 25% that is the HA default.

I was thinking about anchors but I still donā€™t understand how it works

ā€¦
entities:
  - entity: sensor.sm_g780g_battery_level
    ā€¦
    card_mod: &ref
      style: ā€¦
  - entity: sensor.s22_battery_level
    ā€¦
    card_mod: *ref

I canā€™t work out why I canā€™t get rid of the header in this card. could someone give me any pointers?

In general: Post the dom-tree and not (only) the css-picker as screenshot. And secondly the code as code and not as screenshot.

But to shorten the follow up. Even if I donā€™t use this card, the header will be as always inside a shadow root. I assume you will see it in the dom. ave a look in the many same q&a in this thread.

card_mod:
  style:
    $: |
      .card-header { display: none !important }

Hello all,

I am searching for a way to change the color of the value (under the gauge) in a Gauge Card.
I know the basics of Card_mod, but I cannot seem to find the correct CSS value to adapt.

What I use now is working, except for the color:

          card_mod:
            style: |
              ha-card {
                height:125px;
                width:195px;
                background: transparent;
                color: red;
              }

Thanks but that didnā€™t work either. Hereā€™s the dom-tree and hereā€™s the code Iā€™ve got at the moment which is working for all other elements, just need to get rid of the header:

type: custom:more-info-card
entity: media_player.spotify_daniel_james_tye
style:
  more-info-media_player$: |
    div.controls {
      margin-top: 6px;
      padding-top: 10px;
    }
    div.background {
      display: none;
    }
    div.basic-controls {
      display: none;
    }
    div.volume {
      display: none;
    }
    div.source-input {
      display: none;
    }
  .: |
    state-card-content {
      display: none;
    }
    ha-card {
      background-color: transparent;
      box-shadow: none;
    }

I donā€™t see anything from my code-snipped in your code. BTW you are quoting other part (svg-misc from Melle) from than you replied to in my case (hiding title). So I donā€™t know, to what are you referring exactly.

Hi,
Trying to get entity text color to change dependent on a temperature sensorā€¦

After googling and testing, I fond some example that can make it happen

This for example changes the temperature for the entity depending on a helper I have (input_number.testljusvare)

type: entities
entities:
  - sensor.kyl_inne_temperature
card_mod:
  style: |
    ha-card {
        color:
    {% set temp = states('input_number.testljusvade') | float %}
    {% if temp <= 45 %} #88fcf9
    {% elif temp <= 47 %} #00c711
    {% elif temp <= 49 %} #fff133
    {% elif temp <= 51 %} #ffad33
    {% elif temp <= 53 %} #ff3333
    {% endif %};
              display: 
    {% if states('input_number.testljusvade') | float > 5 %}
      none;
    {% endif %}
        box-shadow: none;
        background:
    }

Returns for input_number.testljusvarde=51
image
Returns for input_number.testljusvarde=49
image

I only understand the code partially. I canā€™t figre out what ā€œfloatā€¦ā€ and box-shadow and background doesā€¦but that might not matter as long as it worksā€¦

However, I want the entities for my fridges and freezers to indicate if they are at correct temperture by color

Iā€™m using zigbee sensors and custom:multiple-entity-row to be able to display last updated value for the entity last_seen and then the temperature for the temperature sensor.

That code looks like this and works

type: entities
entities:
  - entity: sensor.kyl_inne_last_seen
    type: custom:multiple-entity-row
    name: Kyl inne
    icon: mdi:fridge-variant
    show_state: false
    secondary_info: last-updated
    entities:
      - entity: sensor.kyl_inne_temperature
        name: false

returns
image

Them I want all text to be:
*** green below <=4 Ā°C***
*** yellow for 4-6 Ā°C***
*** red >6***

Tried this (used my virtual sensor/input_number helper to test) and colors from the example above - but this doesnā€™t work:

type: entities
entities:
  - entity: sensor.kyl_inne_last_seen
    type: custom:multiple-entity-row
    card_mod:
      style: |
        ha-card {
          color:
          {% set temp = states('input_number.testljusvade') | float %}
          {% if temp <= 45 %} #88fcf9
          {% elif temp <= 47 %} #00c711
          {% elif temp <= 49 %} #fff133
          {% elif temp <= 51 %} #ffad33
          {% elif temp <= 53 %} #ff3333
          {% endif %};
            display: 
          {% if states('input_number.testljusvade') | float > 5 %}
            none;
          {% endif %}
            box-shadow: none;
            background:
          }
    name: Kyl inne
    icon: mdi:fridge-variant
    show_state: false
    secondary_info: last-updated
    entities:
      - entity: sensor.kyl_inne_temperature
        name: false

no repsonse when I change my virtual sensor/input_number_testljusvardeā€¦