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

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)
4 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

I canā€™t thank you enough.
The subject has already driven me crazy.
Your tip works perfectly. :star_struck:

1 Like

guess this is my main issue with mushroom. As its Paulā€™s private project, we recognize the issues we had with HA colors when he first migrated the same technique to HA :wink:

I dont use those. all throughout my configā€™s card_mods and styles on native supporting cards, I use vars like var(ā€“text-color-on) etc etc.

    background-color-on: var(--primary-color)
    background-color-off: var(--card-background-color)

    background-opacity-on: rgba(var(--primary),0.8)
    background-opacity-off: rgba(var(--card-background),0.8)

    text-color-on: var(--card-background-color)
    text-color-off: var(--primary-color)

    icon-color-on: var(--card-background-color)
    icon-color-off: var(--primary-color)

  #    mdc-text-field-fill-color: var(--primary-color) # quickbar header
  active-color: '#F9C536'
  accent-color: '#1A78C2'


  primary-color: '#1675C9' 
  primary: 22,117,201
  card-background-color: '#434954'
  card-background: 67,73,84

Mushroom would require adding a whole bunch of identical colorings, have to think about that how to do that most efficiently.

maybe fiddling with the primary and card-background directly

its a same though the card does not simply adhere to HA defaultsā€¦
anyeays, thanks a bunch for the primer (I might have to get back t itā€¦) . maybe you and Ildar can make a post on Mushroom and add it to the top overview post? At least Pin this one!

It would help a lot of people, since the cards is so different.

1 Like

Can somebody help me out?
Trying to fix this after latest 2023.03

This was working pre 2023.03:

card-mod-more-info-yaml: |
  .: |
  @media screen and (min-width: 599px) {
    div[data-domain="camera"] { --mdc-dialog-max-width: 85vw !important; }
    div[data-domain="camera"] div[slot="heading"],
    div[data-domain="camera"] ha-header-bar,
    div[data-domain="camera"] mwc-tab-bar { 
      display:none !important; 
    }
  }

After 2023.03:

It was workingā€¦ but with new models i cant style upper parent div because it has no more ā€˜data-domain=ā€œcameraā€ā€™ attribute at ha-dialogā€¦ thats deeper in the tree now.

I was playing with ::slotted :has :host etcā€¦ but im kinda lost.

I wanted to remove header but only for camera stream popup and make it larger by: ā€˜ā€“mdc-dialog-max-width: 85vw !important;ā€™

I was trying like:

"$ .mdc-dialog__surface":
  .: |
    * > ::slotted(*:nth-child(2):has(div[data-domain="camera"])) {
      border: 1px solid green;
    }

Blockquote

so I am now completely confusedā€¦

while this is working on a tile card:

  - type: tile
    entity: light.dining
    icon: mdi:silverware
    card_mod:
      style: |
        ha-card {
          background: var(--background-color-on)
        }

and the same for the var(--background-color-off) obviously

this isnt:

    card_mod:
      style: |
        ha-card {
          background: >
            {% if is_state('light.dining','on') %} var(--background-color-on)
            {% else %} var(--background-color-off)
            {% endif %};
        }

in any variant, Ive also use the inline syntax I always use:

    card_mod:
      style: |
        ha-card {
          background: >
            {{'var(--background-color-on)' if is_state('light.dining','on')  else 'var(--background-color-off)' }};
        }

what am I missing here?
In the end, want to replace the verbose entity with config.entity, but need to get this working firstā€¦
please have a look? thx!

edit

this does work:

      card_mod:
        style: |
          ha-card {
            {{'background: var(--background-color-off)' if is_state(config.entity,'off')
              else 'background: var(--background-color-on)' }};
          }

and that is unexpected. I dont think I encountered this requirement before, and ,mostly (if not always) have the element outside the template.
this is particularly inconvenient because how to set the color element nowā€¦

would you believe this to workā€¦??

      card_mod:
        style: |
          ha-card {
            {{'background: var(--background-color-off)' if is_state(config.entity,'off')
              else 'background: var(--background-color-on)' }};

            --primary-text-color: {{'var(--background-color-on)' if is_state(config.entity,'off')
              else 'var(--background-color-off)' }};
          }

now how can that be.

note: --primary-text-color also set secondary-text it the latter isnt explicitly set, which is nice.

really bugged about the background now. Why donā€™t I get that

Is there a way to have the size of text within a mushroom template card adjust automatically to fill the available space?

I have a card that displays my local weather forecast. Sometimes, itā€™s as simple as, ā€œSunny. High near 70.ā€ Ideally, that would be displayed in a large font within a box that is, say, 100px tall.

Other times, the forecast will be something like, ā€œA chance of rain showers after 1am. Mostly cloudy, with a low around 40. Chance of precipitation is 50%. New rainfall amounts less than a tenth of an inch possible.ā€ Ideally, that would be displayed in a smaller font within that same box.

My current solution is to use a font size that works well enough, but that leaves some empty white space (most of the time) or pushes the next card slightly off the edge of the tablet screen (sometimes):

type: custom:mushroom-template-card
primary: ''
secondary: '{{ state_attr(''weather.knyc_daynight'', ''forecast'')[0].detailed_description }}'
icon: ''
entity: weather.knyc_daynight
tap_action:
  action: more-info
fill_container: true
multiline_secondary: true
card_mod:
  style: |
    ha-card {
      --card-secondary-font-size: 20px;
      --card-secondary-font-weight: bold;
      margin: -7px -2px
    }

A second question - is there any way to add a chip or additional template info to a mushroom climate card? Our (new) thermostats donā€™t always seem to match reality, so itā€™d be awesome if I could add the output of a separate Aqara sensor in the highlighted space.

image

Most probably, without test, because of this. As always, try to test output in developer tools. It is not background: > etc etc

bingo!

Ofc I did test those templates in dev tools, but that doesnt catch the multiline indicator though.

can confirm:

      card_mod:
        style: |
          ha-card {
            background: {{'var(--background-color-off)' if is_state(config.entity,'off')
              else 'var(--background-color-on)' }};

            --primary-text-color: {{'var(--background-color-on)' if is_state(config.entity,'off')
              else 'var(--background-color-off)' }};
          }

to work also. Nice, and thanks for you keen eye Arganto!

1 Like

This will become a bit easier soon with color-mix. Shipping in Chrome 111 in a few days.