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

  - type: markdown
    content: |-
      <p>Read:</p>
      <p>The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.<br>
      The quick brown fox jumps over the lazy dog.</p>
      
      End!
    card_mod:
      style:
        ha-markdown $: |
          p:nth-child(2) {
            max-height: 200px;
            overflow-y: auto;
          }

image

2 Likes

elif Instead elseif

type: vertical-stack
cards:
  - type: alarm-panel
    states:
      - arm_night
      - arm_away
    entity: alarm_control_panel.9000_aaa_zone_1_alarm
    card_mod:
      style:
        .: |
          ha-card {
            background-color:
            {% if is_state('alarm_control_panel.9000_aaa_zone_1_alarm', 'disarmed') %} 
            red; 
            {% elif is_state('alarm_control_panel.9000_aaa_zone_1_alarm', 'armed_away') %} 
            blue;
            {% elif is_state('alarm_control_panel.9000_aaa_zone_1_alarm', 'armed_night') %}
            green;
            {% else %}
            yellow;
            {% endif %}
            }
        ha-chip:
          $: |
            div:nth-child(1) {
                {% if is_state("alarm_control_panel.9000_aaa_zone_1_alarm", "disarmed") %}
                  background-color: green;
                {% elif is_state("alarm_control_panel.9000_aaa_zone_1_alarm", "armed_away") %}
                  background-color: red;
                {% elif is_state("alarm_control_panel.9000_aaa_zone_1_alarm", "armed_night") %}
                  background-color: orange;
                {% elif is_state("alarm_control_panel.9000_aaa_zone_1_alarm", "triggered") %}
                  background-color: red;
                {% else %}
                  background-color: grey;{% endif %} }
1 Like

I know. And the reason for quoting it as well. And the hint to check template playground in dev-tools.
Helping people help themselves. And as he already replied with thanks and heart, it was solved already.

those templates can be made a lot simpler, and cut all that repetitive code, try something like this:

{% set status = states('alarm_control_panel.9000_aaa_zone_1_alarm') %}
{% set colors = {'disarmed':'red','armed_away':'blue','armed_night':'green'} %}
{{colors.get(status,'yellow')}}
1 Like

that Is a cool mod, and yes, I get it to work on actual lines of text. However, using that on a template returning a long list if text doesnt work.

I did play around bit in the markdown, as adding a white line here or there makes a lot of difference. I could not get it to get better than this though:

    - type: markdown
      card_mod:
        style:
          ha-markdown $: |
            p:nth-child(2) {
              max-height: 200px;
              overflow-y: auto;
            }
      content: |-
        <p>

        {% set comp = state_attr('sensor.overview_components','components') %}
            {% set sub = state_attr('sensor.overview_components','subdomains') %}
            Components: {{comp}} | Subdomains: {{sub}}

        </p>

        <p>

        {{state_attr('sensor.overview_components','per domain')}}

        </p>

compare that to the post above with the unformatted template card, or this somewhat more elaborate card using some folding and separate markdowns:

type: entities
title: Components and domains
card_mod:
  class: class-header-margin
entities:
  - type: custom:hui-element
    card_type: markdown
    card_mod: &no-box
      style: |
        ha-card.type-markdown {
          box-shadow: none;
          margin: 0px -16px;
        }
    content: >
      {% set comp = state_attr('sensor.overview_components','components') %}
      {% set sub = state_attr('sensor.overview_components','subdomains') %}
      Components: {{comp}} | Subdomains: {{sub}}
  - type: custom:fold-entity-row
    head:
      type: section
      label: Per domain
      card_mod: &label
        style: |
          .label {
            margin-left: 0px;
          }
    padding: 0
    entities:

      - type: custom:hui-element
        card_type: markdown
        card_mod: &scroll
          style: |
            ha-card.type-markdown {
              box-shadow: none;
              overflow-y: scroll;
              height: 450px;
              margin: 0px -16px;
            }
        content: >
          {{state_attr('sensor.overview_components','per domain')}}

  - type: custom:fold-entity-row
    head:
      type: section
      label: Per Subdomain
      card_mod: *label
    padding: 0
    entities:

      - type: custom:hui-element
        card_type: markdown
        card_mod: *scroll
        content: >
          {{state_attr('sensor.overview_components','per subdomain')}}

Mar-02-2023 12-51-09

Your answer doesnā€™t help anyone, if you donā€™t feel like it donā€™t

Hi, can I add some perspective to state-label? I would like the text to match the perspective of the wall that is underneath

Perhaps my request to point out my error was overlooked among the many requests in this thread.
In the meantime I have also applied the latest hints in this thread but none led to success.
Any idea what is wrong with my config?

  - type: image
    entity: cover.velux_window_roof_window
    state_image:
      open: /local/ui/floorplan/lite-on.png
      closed: /local/ui/floorplan/lite-off.png
      half-open: /local/ui/floorplan/lite-unavailable.png
    style:
      top: 5%
      left: 50.5%
      width: 2%
    tap_action:
      action: fire-dom-event
      browser_mod:
        service: browser_mod.popup
        data:
          title: roof-window
          content:
            type: custom:shutter-row
            entity: cover.velux_window_roof_window
            name: Garden
            invert_position: false
            state_color: true
            card_mod:
              style: |
                ha-card { border: yes; padding: 100px; }

Picture of the DOM Navigation
image

Cannot test it myself - but play with something like ā€œtransform: rotateā€ with a native ā€œpicture-elements::styleā€ feature (i.e. not card-mod, check this for hints). I think a ā€œperspectiveā€ may be achieved by combination of different rotation. Tests are needed.

You can with transform: skew, like this:

type: picture-elements
elements:
  - type: state-label
    entity: sensor.lounge_sensor_temperature
    style:
      top: 50%
      left: 15%
      font-size: 20px
      color: white
      transform: skew(20deg, -45deg)
5 Likes

maybe first tell us what you would have expected and what doesnt work? help us help you.

Why is it ā€˜wrongā€™?

unless you want us to notice the border: yes, which is not a supported option according to CSS Borders

do we already have a quick overview of the moddable elements in a mushroom-template-card?

Ive been trying to set some colors, according to my regular theming, but apparently the mushroom out of the box only supports a handful of colors.
therefor, we need to go to card_mod, but then require the elements to mod, and those seem to be very well/deeply hidden in Inspector.

I can set a background (given this is after all a button-card, it would make sense it worked)

            type: custom:mushroom-template-card
            card_mod:
              style: |
                ha-card {
                  pointer-events: none;
                  background: var(--primary-color);
                }

but I can not set color: green or an icon color for that matterā€¦

its really odd to find a card not able to support color: var(--primary-color) but there we are. So how to mod those on the mushroom-template-cardā€¦

for starters:

            type: custom:mushroom-template-card
            card_mod:
              style: |
                ha-card {
                  pointer-events: none;
                  background: ivory;
                }
            icon_color: green
            fill_container: true
            layout: vertical

results in:

I would at least require the element for icon (to be able to use a theme var) the primary element (name) and secondary element (number in this case)

I hope, that if I can set a var to the icon, the card will compute the background of the icon itselfā€¦

Where can i learn about how to modify things with css? How do you know all these commands? Thank you very much for your answer !!

Brilliant))))

1 Like

[quote=ā€œoneteam, post:4379, topic:120744ā€]

I am sorry that I did not express myself precisely enough.
The point is that I want to change the appearance of my pop-up map using card_mod.
Colour and size.
For the sake of simplicity, I have only given the size and the frame as examples.
I understand that the frame is a bad example because it is not covered by the CSS element.
What about the padding?

           card_mod:
              style: |
                ha-card { 
                   padding: 100px !important;
                   }

The above example has no effect on the map. If I change it in the Chrome Developer Mode window, it works.
image

There are a lot of great resources, such as W3Schools or MDN.

For me the best way to learn is to have a test dash that I can create cards and play with the CSS in there and figure out how things work. Also have a look at the examples that @Ildar_Gabdullin and others have created. You can copy and paste these into your test dash to see how and why things work.

1 Like

I am using exactly same 2 websites, they covered 90% of cases.

1 Like

Thatā€™s a bit of a strange one. For some reason card_mod is not getting applied to ha-card. It works in the preview, but not in the dash. You can work around it with mod-card, like this:

tap_action:
  action: fire-dom-event
  browser_mod:
    service: browser_mod.popup
    data:
      title: roof-window
      content:
        type: custom:mod-card
        card:
          type: custom:shutter-row
          entity: cover.velux_window_roof_window
          name: Garden
          invert_position: false
          state_color: true
        card_mod:
          style: 
            shutter-row$: |
              ha-card { 
                  padding: 100px !important;
                  border: 1px solid red;
              }

Hey Marius, you can do this:

type: custom:mushroom-template-card
primary: Mushroom
icon: mdi:mushroom
icon_color: var(--rgb-primary-color)

icon_color needs to be RGB as Mushroom Cards use rgba() for the Icon Shape. You can also do icon_color: 255,0,255 etc.

The basic structure of every card is the same, with --icon-color and --shape-color under mushroom-shape-icon. There is also --icon-color-disabled, --icon-shape-disabled and --shape-outline-color that can be used. These can be any valid color, but you would need to handle the opacity for the Shape colors.

type: custom:mushroom-template-card
primary: Mushroom
icon: mdi:mushroom
card_mod:
  style: |
    mushroom-shape-icon {
      --icon-color: rgb(var(--rgb-orange)) !important;
      --shape-color: rgba(var(--rgb-orange), 0.2) !important;
    }

For most of the cards there is a --rgb-state-[card_type] variable that can be used, and sets the color for both the Icon and the Shape. This needs to be a RGB color.

For Primary Text the variable is --primary-text-color and for Secondary Text it is --secondary-text-color.

For the entity card it is --rgb-state-entity:

type: custom:mushroom-entity-card
entity: input_boolean.mushroom
card_mod:
  style: |
    ha-card {
      --rgb-state-entity: 255,0,0;
      --primary-text-color: darkgreen;
      --secondary-text-color: chartreuse;
    }

You can also use --mush-rgb-state-[card_type] in your theme or in :host:

type: custom:mushroom-entity-card
entity: input_boolean.mushroom
card_mod:
  style: |
    :host {
      --mush-rgb-state-entity: 255,0,255; 
    }

The `ā€“mush-* variables are mostly documented in Paulā€™s Mushroom Theme Github:

I have posted some examples in the Mushroom Thread, have a look through my posts there. :grin:

1 Like