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

Hey, Iā€™m stuck on changing the text size of only the first line in the Digital-Clock card from hacs, I can make both lines of text bigger but I only want to make the first line (time) bigger

code:

type: custom:digital-clock
timeFormat: h:mm a
card_mod:
  style:
    digital-clock$: 
      $: | 
        span {
          font-weight: 1000;
          #color: #B6FC00;
          font-size: 25px !important;
          }

this is the code that will make both lines larger

type: custom:digital-clock
timeFormat: h:mm a
card_mod:
  style: |
    ha-card {
      font-weight: 1000;
      #color: #B6FC00;
      font-size: 25px !important;
       }

any help would be great. thank you

type: custom:digital-clock
timeFormat: h:mm a
card_mod:
  style: |
    .first-line {
      font-weight: 1000;
      #color: #B6FC00;
      font-size: 25px !important;
       }

Yes of course. And I posted everything already at šŸ”¹ Card-mod - Add css styles to any lovelace card - #6750 by e-raser.

But I found the root cause:
state_color has been true which overrides every manually applied CSSā€¦ :roll_eyes: false fixed it immediately.

This is working now (state-badge applies):

                  card_mod:
                    style:
                      hui-generic-entity-row:
                        $: |
                          .text-content:not(.info) {
                            display: none;
                          }
                          .info.pointer {
                            #color: red;
                            font-size: 18px;
                          }
                          state-badge {
                            color: red;
                          }

Thank you! that did the trick.

(Un)popular opinion: this thread will soon be flooded by people complaining about badge and/or badge-card. Just wait for next Wednesday, August 7th

why? has nothing to do with card-mod perse?

btw, as a heads up: we can keep using the built-in legacy badge (and also keep using the custom:badge-card to put them anywhere in the View) doing

badges:
      - type: custom:hui-state-badge-element
        entity: light.alarm
        tap_action:
          action: toggle
        hold_action:
          action: more-info

not an actual custom resource, itā€™s just the way to call that core element still existing in the Frontend

current beta testing 2024.8.0b1

ofc, styling the new badge is an entirely different thingā€¦

1 Like

Yeah, thatā€™s what Iā€™m talking about :slight_smile:
People who will want to customize the new badges, trying to use the (soon to be) old card-mod tutorial that can be found here.

EDIT: you can use custom:hui-state-badge-element for legacy look but the good olā€™ fashion card-mod syntax for badge like the example bellow will not work without a bit of research

      card_mod:
        style: |
          :host {
              {% if is_state('input_boolean.stop_ipad', 'off') %}
                --label-badge-background-color: rgba(0,255,0,0.1);
              {% else %}
                --label-badge-background-color: rgba(255,0,0,0.1);
              {% endif %}
          }

EDIT2: And, yes, Iā€™m reasearching right now for both legacy look and new look, that why I donā€™t have a working code (yet)

1 Like

Does anyone know how to change the color of the progress bar?

card_mod:
  style: |
    ha-card {
     # --ha-card-background: grey;
      opacity: 70% ;
      color: var(--primary-color);
    }

This has probably already been asked a 1000 times, but I wasnā€™t able to get it to work with the posts I found.

Basically, I have this card (see above), I now I just like to change the icon for binary_sensor.gate_door_position_sensor, when the gate is ā€œopenā€, show icon AA, when the gate is ā€œclosedā€, show icon BB.

Thanks!

type: custom:mushroom-entity-card
fill_container: true
layout: vertical
name: Tor
secondary_info: none
entity: binary_sensor.gate_door_position_sensor
icon: ''
tap_action:
  action: call-service
  service: automation.trigger
  target:
    entity_id: automation.unifi_access_api_tor_offnen
  data:
    skip_condition: true
primary_info: none
card_mod:
  style: |
    :host {
    padding-top: 15px!important;
    }
       @media (prefers-color-scheme: dark) {
          ha-card:hover {
            background-color: #222222 !important;
          }
          ha-card {
            transition-duration: .0s !important;
          }
        }
        @media (prefers-color-scheme: light) {
          ha-card:hover {
            background-color: #F6F6F6 !important;
          }
          ha-card {
            transition-duration: .0s !important;
          }
        }

right, I hadnā€™t even started doing that ;-0

did find these variables to be functional in themes:

#badge
    label-badge-background-color: brown
    label-badge-text-color: green
    ha-label-badge-font-size: 15px
    label-badge-red: '#03a9f4'
    ha-label-badge-size: 30px
    ha-label-badge-border-radius: 0

#label below badge
    ha-label-badge-label-color: red
    ha-label-badge-label-background-color: red

#title below badge/label
    ha-label-badge-title-font-size: 8px
    ha-label-badge-title-font-weight: 400
    ha-label-badge-title-width: 50px

dont mind the settings I set, its just for experiment. And, ofc, not yet dynamic, or s complete as I managed before

btw this is the source frontend/src/components/ha-label-badge.ts at 62d8434596535625d743efc532ebf3a34f4a7144 Ā· home-assistant/frontend Ā· GitHub

so the badge label doesnt have a border-radius variable of its own, which is a bit a pity, and reason we need to travers the Dom for thatā€¦ Havent found a way to set different colors on the borders either. we could do that for the badge and the label individually before.

Badges may change its structure within next versions, look at the Tile card which had some changes.

Yes that is indeed a risk to be considered.

Still trying to work my way through the new Tile card features changes to get the border-radius backā€¦
Team simply says thatā€™s unsupported undocumented so weā€™re on our own thereā€¦

Find that somewhat user unfriendly myself (after all why take the trouble to announce a warning on the changes, but leave the changes themselves unmentioned) but will probably work it out anyways :wink:

Yes, it is changing in this 2024.8.0 release.
For who is using

          card_mod:
            style:
              hui-card-features$:

There will be a new level to add, right after hui-card-features

          card_mod:
            style:
              hui-card-features$:
                hui-card-feature$:  
1 Like

yes, that is itā€¦
How could I have missed that, been looking at those dom paths for 2 days nowā€¦ aargh, and such a useful new path it is :wink:

you really made my day here, thank you very much

I will change immediately the overview of features mods I posted above

would you happen to know if we could use those vriables directly:

# Tile features generic setting
    feature-border-radius: 0
    control-slider-border-radius: 0
    control-button-border-radius: 0
    control-select-border-radius: 0
    control-select-button-border-radius: 0
    control-select-menu-border-radius: 0

they are used in the cards, but I cant touch them from within my main themes, which would be just as nice as the state-colors.

Should be something like this I guess (not tested):

                    card_mod:
                      style:
                        hui-card-features $:
                          hui-card-feature $:
                            hui-cover-position-card-feature $: |
                              ha-control-slider {
                                --control-slider-border-radius: 10px !important;
                              }

The same applies for the other hui-xxx-card-feature (I hope)

EDIT: to use theme variable, it is something like

--control-slider-border-radius: var(name_of_variable_from_theme) !important;

yes, and I tried both:

first of all, just setting those variables in a theme, which would then be picked up by the cards, as their default values for these variables are the ones I posted above, var(--feature-border-radius). That doesnā€™t work.

Then I tried the mods as you post above:

--control-slider-border-radius: var(--control-slider-border-radius)

or with the var(--feature-border-radius) . Doesnt work either.

So, for now, we can only use either a true px number there, or the variabel we Can use from themes:

style:
  hui-card-features $:
    hui-card-feature $:
      hui-cover-open-close-card-feature $:
          ha-control-button$: |
            .button {
              --control-button-border-radius: var(--ha-card-border-radius);
            }

      hui-cover-position-card-feature $:
        ha-control-slider$: |
          .container {
            --control-slider-border-radius: var(--ha-card-border-radius);
          }
          .slider .slider-track-bar {
            border-radius: var(--ha-card-border-radius) !important;
          }
          .slider .slider-track-bar::after {
            border-radius: var(--ha-card-border-radius) !important;
          }

Still strikes me as odd we cant override that system variable, and maybe the future will allow us to do so.

You can, you have to create your own theme, you can even include some card-mod default that will apply to every cards (wrong exemple, as it refers to badges that will change in 2024.8.0 but you get the idea)

midnight2:

  card-mod-theme: midnight2
  card-mod-view-yaml: |
    hui-masonry-view $: |
      .badges {
        margin-top: auto !important;
        font-size: 90%;
      }
    .: |
      hui-masonry-view {
        display: flex;
        flex-direction: column-reverse;
        justify-content: start;
        align-items: center;
      }


# Main colors
...

EDIT: Donā€™t forget that card-mod is coming after everything else, therefore, if it was already defined/inherited by something else, you need to !important to override the value

sure it get the example :wink:

I use those card-mod-themes since forever, no mysteries there. well, most of it is clear anywaysā€¦

what I meant is, we can set values on the system variables like

    ha-card-border-width: 0
    ha-card-border-color: transparent # test this is even necessary with width = 0?
    ha-card-border-radius: 0
    ha-dialog-border-radius: var(--ha-card-border-radius)
    ha-config-card-border-radius: var(--ha-card-border-radius)

and it will get applied to all views/cards that use these variables.

doing the same with the tile card variables

# Tile features generic setting
    feature-border-radius: var(--ha-card-border-radius)
    control-slider-border-radius: 0
    control-button-border-radius: 0
    control-select-border-radius: 0
    control-select-button-border-radius: 0
    control-select-menu-border-radius: 0

simply doesnt work, it seems unrecognized, and we need to resort to card-mod like I posted above. Card-mod remains a very important tool in the box, even though using that feature-border-radius would be way simpler

you can also use the :host to override system values for the card

                    card_mod:
                      style: |
                        :host {
                          --feature-border-radius: 0px !important;
                        }

no?

EDIT: Sorry, Iā€™m blindly helping, I had to remove 2024.8.0b3 because Alexa Media Player is failing to initialize (since b0). So Iā€™ve no way to test and check what Iā€™m giving you.

1 Like

Let me test that again , I did some initial testing on that without success

Also, I think the details on the sliders donā€™t use that variable .

Thatā€™s what my tile mods are a bit involvedā€¦

Thanks! Iā€™ll be back

Haha, thats a bummer indeed for many users right now.

Ive tried that again though, and no, it does not work.
I ll stick with the changes you suggested earlier, they are super reliable at this point.
Fingers crossed they dont change that again.