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

Did you actually put entities in there? I think that the entities card is a bad example, because each item is under its own shadow-root.

For example I have:

type: weather-forecast
style: |
  ha-card {
    color: red;
  }
entity: weather.domek

Result is the same. No red color ;(

I believe shadow roots are used there as well. Try background-color instead.

I think that this may be an issue, the message in console:

card-mod.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of ā€œtext/htmlā€. Strict MIME type checking is enforced for module scripts per HTML spec.
chunk.50aa61d1621a20ca8a1a.js:575 Uncaught (in promise) http://192.168.1.200:8123/config/www/community/lovelace-card-mod/card-mod.js

Any ideas?

Yup, you downloaded the whole HTML page instead of just the raw JS.

I was not downloading itā€¦ I installed it via HACS.
When I do cat card-mod.js I see that it starts with !function(e) ā€¦ so itā€™s pure JS file.

What did you include in your resource file? I think you should check the magic numbers (thatā€™s how Linux dictates file type.)

My config:

Nope, HACS didnā€™t add that resource automatically. Itā€™s /local/, not /config/www/.

Iā€™ve removed and installed it once again via HACS and once again it was put in that place. On the HACS page I can see that this is the default place of installed modules.

Should i move it to local? (I donā€™t have this path either)

/config/www/ on your file system maps to /local/ on the web browser, for example myhome.duckdns.org/local/community/lovelace-card-mod/card-mod.js, but HACS should auto-add it at /hacsfiles/lovelace-card-mod/card-mod.js.

Once replaced /config/www/ by /local/ it works like a charm! I own you a beer :slight_smile: Thanks

If you used HACS it SHOULD be /hacsfiles/button-card/button-card.js

1 Like

Hello
can you tell me why this doesnā€™ work ?((((


Background color = OK, but ā€œheightā€ is ignoredā€¦

type: entities
entities:
  - entity: sun.sun
title: height
style: |
  ha-card {
    height: 500px;
    background: rgb(0,255,0);
  }

:one::six: Should I tag people?

Generally, no.

It comes across as bad manners, youā€™re demanding somebody answers you. Itā€™s different if youā€™re thanking somebody, obviously.

How to help us help you - or How to ask a good question

1 Like

I finally updated from HA 116.4 to 117.1. I see that markdown has yet again changed stuff. I canā€™t set the card height anymore with card mod. I used to have this:

IMG_0997

now it shows as this:
msedge_RD6HhRusOq

I created this by putton two markdown cards inside a vertical-stack. The ā€˜headerā€™ has this style:

  .: |
    ha-card {
      height: 20px;
      --ha-card-background: none !important;
      box-shadow: none !important;
      left: -2.5%;
      width: 100vw;
    }
  ha-markdown:
    $: |
      h1 {
        font-size: 20px;
        font-weight: bold;
        font-family: Helvetica;
        letter-spacing: '-0.01em';
      }
  

And the ā€˜subā€™ has this stile:

  .: |
    ha-card {
      height: 30px;
      --ha-card-background: none !important;
      --primary-text-color: var(--sensor-accent-color);      
      box-shadow: none !important;
      left: -1.2%;
      
    }
  ha-markdown:
    $: |
      h1 {
        font-size: 15px;
        font-weight: thin;
        font-family: Helvetica;
        letter-spacing: '-0.01em';
      }
      

It looks like the height code has changed? Does anyone know how I can fix this again?

Edit:

I see a second style (constructed stylesheet) option with height: 100%, that one disables my height setting. If i uncheck that one, all works. I tried setting that, but I have no clue how to change that and what to put for card-mod to use it. Any idead?
msedge_QEOJYalDvR

This part breaks my entire setup since I use markdown all over the place. Removing the line solves everything. Anyone know what I can do to make sure HA ignores that line in my entire UI?

For the time being I fixed it by using !important everywhere, which now overrides the new variable. Though this is very hacky and doesnā€™t look nice when reloading (starts spaced then applies the height). I really hope some has a decent global solution for this.

Edit: I created a ticket at HA Frontend. If someone else uses markdown this way, stay up to date here -> https://github.com/home-assistant/frontend/issues/7578#issuecomment-720539351

Has something changed with this mod card?
My center buttons with picture entity card in it, is now bigger than the rest, although the code is the sameā€¦ (this used to work, but something changed and they arent equal size anymore

Has something changed with this mod card?
My center buttons with picture entity card in it, is now bigger than the rest, although the code is the sameā€¦ (this used to work, but something changed and they arent equal size anymore

The code:

- card:
          name: Alarm
          type: button
          show_label: false
          icon: mdi:shield-off
          tap_action: !include popup/alarm.yaml
            
        style: |
          ha-card {
            height: 128px;
            text-align: center;
          }
        type: 'custom:mod-card'
      - entity: person.stijn
        image: /local/stijn.jpg
        tap_action: !include popup/persoon1.yaml
        style: |
          ha-card {
            height: 128px;
          }
        type: picture-entity
      - card: 
          name: Verlichting
          type: button
          icon: mdi:lightbulb-outline
          tap_action: !include popup/verlichting.yaml
        style: |
          ha-card {
            height: 128px;
          }
        type: 'custom:mod-card'

Any ideas on which level I should put style to be able to modify div with columns?
I put it like that:

  - icon: 'hass:chart-line'
    title: Charts
    path: charts
    panel: false
    style: |
      #columns {
         justify-content: end !important;
         }
    badges: []
    cards:
      - type: history-graph

but itā€™s not taken into account.

What type of card is that?

true that, but then I get yellow icons when it is onā€¦ I would really want red iconsā€¦

I tried some thingsā€¦ and am partial succesfull

code:

type: glance
entities:
  - entity: binary_sensor.laadpaal_jc_l
    style: |
      :host {
        --paper-item-icon-color: 
          green;
      }
       
  - entity: binary_sensor.laadpaal_jc_r
    style: |
      :host {
        --paper-item-icon-color:
          {% if states('binary_sensor.laadpaal_jc_r') == 'on' %}
            red;
          {% else %}
          {% endif %}
            }
  - entity: binary_sensor.laadpaal_jc_r
    style: |
      :host {
        --paper-item-icon-color:
          {% if states(config.entity) == 'on' %}
            red;
          {% else %}
          {% endif %}
            }

result:
Screenshot 2020-11-02 at 10.07.12

What is wrong?