🔹 Card-mod - Add css styles to any lovelace card

Seems that you applied a style to a wrong element - rotation is not centered, there is a shift.

Cannot react on this, know nothing about card-mod-themes…

Same on my setup, strange.

yes, ofc I noticed that, thought it might be the icon not being perfectly centered. Its the same in Chrome. And the code is the exact code you use…

Yesterday was the 2nd time I experimented with layout-card - it is better to discuss these issues in a corresponding thread.

That is why I wrote that this is not the best solution…
I do not know how to align controls automatically.

1 Like

on the coloring of the template-entity-row entity’s icon:
for the sake of experiment (and see if the code itself is corrrect) I changed to:

              @keyframes coloring {
                0% {
                  background: red;
                }
                17% {
                  background: orange;
                }
                34% {
                  background: yellow;
                }
                51% {
                  background: green;
                }
                68% {
                  background: lightblue;
                }
                85% {
                  background: blue;
                }
                100% {
                  background: violet;
                }

which looks like:
Nov-19-2021 15-10-31
in Safari, and

Nov-19-2021 15-13-21
in Chrome.

which could proof to be useful as a way around the issue…

Thank you, I will :slight_smile:
As a first feedback, I can say that the solution for the width issue was using layout_type: custom:grid-layout. This also does not require me to define the width.

This is an old issue.
Now I am using this style in my setup for each row:

                hui-generic-entity-row {
                  margin-top: 0px;
                  margin-bottom: 8px;
                }

See the difference here:

type: horizontal-stack
cards:
  - type: entities
    entities:
      - type: section
        label: persons
      - entity: person.ildar
      - entity: person.mama
      - entity: person.papa
  - type: entities
    entities:
      - type: custom:fold-entity-row
        head:
          type: section
          label: persons
        padding: 0
        open: true
        entities:
          - entity: person.ildar
          - entity: person.mama
          - entity: person.papa
  - type: entities
    entities:
      - type: custom:fold-entity-row
        head:
          type: section
          label: persons
        padding: 0
        open: true
        entities:
          - entity: person.ildar
          - entity: person.mama
          - entity: person.papa
    card_mod:
      style:
        fold-entity-row:
          $:
            div#items hui-text-entity-row:
              $: |
                hui-generic-entity-row {
                  margin-top: 0px;
                  margin-bottom: 8px;
                }

image

Earlier this style worked too but stopped working (the issue):

  - type: entities
    entities:
      - type: custom:fold-entity-row
        head:
          type: section
          label: persons
        padding: 0
        open: true
        entities:
          - entity: person.ildar
          - entity: person.mama
          - entity: person.papa
        card_mod:
          style:
            div#items hui-text-entity-row:
              $: |
                hui-generic-entity-row {
                  margin-top: 0px;
                  margin-bottom: 8px;
                }

Update (20.11.21):
The “tight vertical spacing” problem is solved in fold-entity-row ver. 2.0.12
:star_struck: :star_struck: :star_struck: :star_struck:

Test exactly this code and tell me about the difference please:

type: entities
entities:
  - type: custom:template-entity-row
    entity: sun.sun
    name: name
    secondary: some value
    state: state
    icon: mdi:fan
    card_mod:
      style:
        div#wrapper: |
          state-badge {
            animation: rotation 0.5s linear infinite, resizing 1s linear infinite alternate, coloring 8s linear infinite alternate;
          }
          @keyframes rotation {
            0% {
              transform: rotate(0deg);
            }
            100% {
              transform: rotate(360deg);
            }
          }
          @keyframes resizing {
            0% {
              --mdc-icon-size: 10px;
            }
            25% {
              --mdc-icon-size: 15px;
            }
            50% {
              --mdc-icon-size: 20px;
            }
            75% {
              --mdc-icon-size: 26px;
            }
            100% {
              --mdc-icon-size: 32px;
            }
          }
          @keyframes coloring {
            0% {
              color: red;
            }
            17% {
              color: orange;
            }
            34% {
              color: yellow;
            }
            51% {
              color: green;
            }
            68% {
              color: lightblue;
            }
            85% {
              color: blue;
            }
            100% {
              color: violet;
            }
          }

qwsder

Icon is coloring (but I have Not customized sun.sun, so not trouble with custom-ui expected :wink: )
Nov-19-2021 16-28-59

the exact card-mod on a boolean (which I have customized) remains without result

But again is not centered (((((((((
There is smth strange with your setup, my friend…
My proposal is - create a CLEAN test setup and check how it works…

will do, and just fired up Firefox as a 3d browser.

On the Folds and vertical spacing:
to give you an idea though, I have 262 fold-entity-rows, and only this card gives me a headache…
I have them populated with auto-entities cards, or listed entities, what have you. given the fact there is now error in the inspector at all on this config, debugging is very difficult.

Figured it out in themes

  card-mod-theme: noctis-grey
  
  card-mod-more-info-yaml: |
    ha-more-info-history:
      $: |
        .header > a, a:visited {
          color: var(--secondary-text-color) !important;
          font-size: 12px;
        }
    ha-more-info-logbook:
      $: |
        .header > a, a:visited {
          color: var(--secondary-text-color) !important;
          font-size: 12px;
        }  

Not that agressive anymore

image

But it is only working here, but not within the tabs like

image

Any hint?

Hello @thomasloven! Thank you very much for the feedback.
Yes, navigation for hui-element became a bit confusing - but I managed to rebuild all my code, it looks fine again!

Please let me know if you find something that doesn’t work. It’s a bit rickety with timing issues right now.

Thomas, now I got only these issues about card-mod:

Thank you again for your valuable work!

P.S. I am creating a post explaining using card-mod for hui-element for different row types as well as using them inside decluttering template with mod-card. This post will be added into the consolidation post.

Styling hui-element card:

This post is about using hui-element card to represent a row inside an Entities card:

  • section
  • sensor-entity
  • number-entity (slider or box)
  • toggle-entity
  • input-select-entity
  • input-text-entity
  • weather-entity
  • buttons
  • conditional row

Here they are (updated 04.03.22 for “chips” buttons and new HA2022.3 design):

Code for the card
type: entities
entities:
  - type: custom:hui-element
    row_type: section
    label: section
  - type: custom:hui-element
    row_type: sensor-entity
    entity: input_number.test_number
    name: sensor-entity
  - type: custom:hui-element
    row_type: number-entity
    entity: input_number.test_number
    name: number-entity (slider)
  - type: custom:hui-element
    row_type: number-entity
    entity: input_number.test_number_2
    name: number-entity (box)
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean
    name: toggle-entity
  - type: custom:hui-element
    row_type: input-select-entity
    entity: input_select.test_value
    name: input-select-entity
  - type: custom:hui-element
    row_type: input-text-entity
    entity: input_text.test_text
    name: input-text-entity
  - type: custom:hui-element
    row_type: weather-entity
    entity: weather.home_met
    name: weather-entity
  - type: custom:hui-element
    row_type: buttons
    entities:
      - entity: sun.sun
        show_name: true
      - entity: sun.sun
        show_name: true
      - entity: sun.sun
        show_name: true
  - type: custom:hui-element
    row_type: conditional
    conditions:
      - entity: input_boolean.test_boolean
        state: 'on'
    row:
      entity: sun.sun
      name: conditional
Why using "hui-element" for rows is very useful? Look at some examples if you do not know yet.
  1. Using a slider or a toggle row inside Picture elements card.
  2. Using section row inside stack-in-card to separate areas.
  3. Making a decluttering template for any row with predefined options & styling.

There are 4 methods of styling hui-element rows:

  1. Using :host - to style a particular row.
  2. Using long DOM navigation - to style a particular row.
  3. Using long DOM navigation from the parent Entities card or Picture elements card level - to style a particular row or all rows.
  4. Using long DOM navigation from the parent mod-card level - to style a row inside a decluttering template.

Using :host - to style a particular row:
Note: the hui-element card is a kind of transparent element - all styles go “directly to the row”.

type: entities
entities:
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored row
    card_mod:
      style: |
        :host {
          color: red;
        }
  - type: custom:hui-element
    row_type: section
    label: section
    card_mod:
      style: |
        :host {
          --divider-color: magenta;
        }
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean
    name: Colored toggle
    card_mod:
      style: |
        :host {
          --switch-unchecked-button-color: yellow;
          --switch-checked-button-color: red;
        }

image


Using long DOM navigation - to style a particular row:
Note: the hui-element card is a kind of transparent element - all styles go “directly to the row”.

type: entities
entities:
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored name
    card_mod:
      style:
        hui-generic-entity-row:
          $: |
            .info {
              color: red;
            }
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean
    name: Colored toggle
    card_mod:
      style:
        hui-generic-entity-row:
          ha-entity-toggle:
            $:
              ha-switch:
                $: |
                  .mdc-switch .mdc-switch__track {
                    background-color: yellow !important;
                    border-color: red !important;
                  }
  - type: custom:hui-element
    row_type: section
    label: section
    card_mod:
      style: |
        .divider {
          background-color: cyan !important;
        }
  - type: custom:hui-element
    row_type: number-entity
    entity: input_number.test_number
    name: Colored state
    card_mod:
      style: |
        hui-generic-entity-row .flex .state {
          color: magenta;
        }

изображение


Using long DOM navigation from the parent Entities card or Picture elements card level - to style a particular row or all rows:

Section:

type: entities
entities:
  - entity: sun.sun
  - type: custom:hui-element
    row_type: section
    label: section
  - entity: sun.sun
  - entity: sun.sun
  - type: custom:hui-element
    row_type: section
    label: section
  - entity: sun.sun
  - entity: sun.sun
card_mod:
  style:
    .card-content hui-element:
      $: |
        .divider {
          background-color: cyan !important;
        }

image

Sensor:

type: entities
entities:
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored name
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored name
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored name
card_mod:
  style:
    .card-content hui-element:
      $:
        hui-generic-entity-row:
          $: |
            .info {
              color: red;
            }

image

Toggle:

type: entities
entities:
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean
    name: Colored toggle
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean_2
    name: Colored toggle
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean_3
    name: Colored toggle
card_mod:
  style:
    .card-content hui-element:
      $:
        hui-generic-entity-row:
          ha-entity-toggle:
            $:
              ha-switch:
                $: |
                  .mdc-switch .mdc-switch__track {
                    background-color: yellow !important;
                    border-color: red !important;
                  }

image


Using long DOM navigation from the parent mod-card level - to style a row inside a decluttering template:

Slider:
Template:

decl_entity_row__slider_xxx:
  card:
    type: custom:mod-card
    card:
      type: custom:hui-element
      row_type: number-entity
      entity: '[[SENSOR]]'
      name: '[[VALUE_NAME]]'
    card_mod:
      style:
        hui-element:
          $: |
            hui-generic-entity-row {
              color: [[VALUE_COLOR_TEXT]];
              --paper-item-icon-color: [[VALUE_COLOR_ICON]];
            }

Using the template:

type: entities
entities:
  - type: custom:decluttering-card
    template: decl_entity_row__slider_xxx
    variables:
      - SENSOR: input_number.test_number
      - VALUE_NAME: "cyan name, magenta icon"
      - VALUE_COLOR_TEXT: cyan
      - VALUE_COLOR_ICON: magenta

изображение

Input-select:
Template:

  decl_entity_row__input_select_xxx:
    card:
      type: custom:mod-card
      card:
        type: custom:hui-element
        row_type: input-select-entity
        entity: '[[INPUT_SELECT]]'
        name: '[[VALUE_NAME]]'
      card_mod:
        style:
          hui-element:
            $:
              hui-generic-entity-row:
                $: |
                  state-badge {
                    color: '[[VALUE_COLOR]]';
                  }

Using the template:

type: entities
entities:
  - type: custom:decluttering-card
    template: decl_entity_row__input_select_xxx
    variables:
      - INPUT_SELECT: input_select.test_value
      - VALUE_NAME: xxxxxx
      - VALUE_COLOR: magenta

изображение


More examples are described here.

4 Likes

Hello,

Anyone could tell me if it is possible to apply a conical gradient to a mdi:checkbox-blank-circle icon ?
Need to represent a “multicolor” button.

Thanks !

Hello,
I have a some question, maybe there I can found a solution.
Firstly, sorry for my english. I home you can understand me.

Im using my own frontend theme, but with frontend update since 2021.11 I got some problem with view of elements.
Seems like more-info dialogs and select menu updated and uses same color source (–mdc-theme-surface).
On my screenshow I show where I have problems.
I just want to leave black transparent color on more-info and browser-mod-popup background (rgba(26,26,26,0.5)), but I want to change color of selection menu in actions/condition of automations and automation menu in automation list.
But if I change --mdc-theme-surface, color change applies for all this elements (including background color of more info, what i dont want to do).

Please, help me, is it possible use card-mod to change mdc-select background color, but leave black background color of dialogs?

--paper-item-icon-color seems to stopped working since HA 2021.11.

Other things still work on the same element (entity icon):

                :host {
                  --paper-item-icon-color: red; # NOT WORKING ANYMORE
                  --mdc-icon-size: 40px; # still working
                }

How to disable a toggle button:
asdfre

type: entities
title: Disabled checkbox
show_header_toggle: false
entities:
  - entity: input_boolean.test_boolean
    name: disabled
    card_mod:
      style:
        hui-generic-entity-row:
          ha-entity-toggle:
            $:
              ha-switch:
                $: |
                  .mdc-switch .mdc-switch__thumb input {
                    pointer-events: none;
                  }
                .: |
                  ha-switch {
                    --switch-unchecked-button-color: var(--disabled-text-color);
                    --switch-checked-button-color: var(--disabled-text-color);
                  }
  - entity: input_boolean.test_boolean
    name: normal

Also, you can “grey” all row’s elements & disable tap_action:
image

  - entity: input_boolean.test_boolean
    name: totally disabled
    tap_action:
      action: none
    card_mod:
      style:
        hui-generic-entity-row:
          ha-entity-toggle:
            $:
              ha-switch:
                $: |
                  .mdc-switch .mdc-switch__thumb input {
                    pointer-events: none;
                  }
                .: |
                  ha-switch {
                    --switch-unchecked-button-color: var(--disabled-text-color);
                    --switch-checked-button-color: var(--disabled-text-color);
                  }
        .: |
          :host {
            color: var(--disabled-text-color);
            --paper-item-icon-color: var(--disabled-text-color);
          }
9 Likes