đŸ”č Card-mod - Add css styles to any lovelace card

#head doesn’t have a shadowroot, so there should’t be a $ there.

There are shadowroots in your way. Look at the post below yours. That’s a great example on how to dissect a selector path.

1 Like

@thomasloven
I still do not understand.
Could you help me?
I deleted $ from #head, but nothing has changed, I can’t get to .label

- title: Test Card Mod
  cards:
    - type: entities
      style:
        .: |
          ha-card {
            border-radius: 10px;
          }
        "#states div":
          fold-entity-row:
            $: |
              "#head":
                entity-row-maker:
                  hui-section-row:
                    $: |
                      .label {
                        color: #FFFFFF;
                      }
      entities:
        - type: custom:fold-entity-row
          head:
            type: section
            label: Test
          items:
            - light.bedroom
            - light.kitchen
            - light.hall

I can’t really say what’s wrong, but I can give you a tip for finding the problem.

Try one step at a time, i.e. start with

style:
  "#states div": |
    whatever {
      color: red;
    }

Then open up the object inspector and make sure the following is added inside the correct <div> tag.

<style class="card-mod-style">whatever {
  color: red;
}
</style>

Then you move on to

style:
  "#states div": 
    fold-entity-row: |
      whatever {
        color: red;
      }

and so on


3 Likes

nevermind.

Cheers!
Now I see where the <style> should be.
Tusen tack for this wonderful card!

- title: Test Card Mod
  cards:
    - type: entities
      style:
        "#states div":
          fold-entity-row:
            $:
             "#head":
               entity-row-maker:
                 hui-section-row:
                   $: |
                     div.label {
                       color: red;
                       font-size: 1.5em;
                       font-weight: bold;
                     }
      entities:
        - type: custom:fold-entity-row
          head:
            type: section
            label: Test Card Mod
          items:
            - light.bedroom
            - light.kitchen
            - light.hall

2 Likes

It does not work on Safari 12.1.1 (macOS 10.14.5)

Chrome


Safari

Here is Firefox.

It is not working for me neither


I’ve just made a new release that should work better in Safari and Firefox.

It also adds the option to print the process of applying styles by adding debug_cardMod: true to the card config. Should help a bit while trying to get things to work.

3 Likes

I’ve got it working great on most cards but cannot get it to work on a horizontal-stack. Its probably something simple I’m missing but I can’t seem to modify it. Specifically I want to be able to add a margin to the horizontal-stack. When I inspect I can modify in an id called #root and add the margins just how I want. Then the cards inside the horizontal-stack are inside a <div id="root">
This is the JSpath to the card:
document.querySelector("body > home-assistant").shadowRoot.querySelector("home-assistant-main").shadowRoot.querySelector("app-drawer-layout > partial-panel-resolver > ha-panel-lovelace").shadowRoot.querySelector("hui-root").shadowRoot.querySelector("#view > hui-view").shadowRoot.querySelector("#columns > div > hui-horizontal-stack-card").shadowRoot.querySelector("#root")

I have tried many combinations to get this working:

style:
  $: |
    #root {
      margin: 9px;
    }
style: |
  #root {
    margin: 9px;
  }
style:
  .:
    $: |
      "#root" {
        margin: 9px;
      }

What am I doing wrong?

I’ve added a section to the readme about this: https://github.com/thomasloven/lovelace-card-mod#why-wont-this-work-for-some-cards

2 Likes

Hi there, I’m trying to get a background gradient for a whole vertical-stack-in-card. My Lovelace theme has some gradient for cards backgrounds and with the vertical stack every card has his own gradient. I would like to get only 1 big background for the full stack. I can’t get it to work with your section FAQ (works for a single color but not for a gradient). Any advice on this ?

It took a bit for my brain to start to grasp some of the advanced styling, and I am still figuring out as I go, but this card really unlocks some awesome possibilities! Here’s something I put together with the mini-media-player and the YAML I used for it:

image

type: custom:mini-media-player
entity: media_player.theater
artwork: full-cover
hide:
name: true
icon: true
style:
.: |
    ha-card > div.mmp-player {
    padding-left: 0px !important;
    padding-right: 0px !important;
    padding-bottom: 0px !important;
    --paper-slider-knob-color: white;
    --paper-slider-active-color: white;
    --paper-slider-container-color: #303741;
    }
    ha-card > div.mmp-player div {
    padding-left: 10px !important;
    padding-right: 10px !important;
    background: rgba(0,0,0,0.8);
    }
    ha-card > div.mmp-player div .entity__info,
    ha-card > div.mmp-player div .entity__info__media {
    background: rgba(0,0,0,0);
    padding: 0px !important;
    }
    ha-card > div.mmp-player div .entity__info__media span:nth-of-type(2)::before {
    content: '\000A' !important;
    white-space: pre !important;
    }
    ha-card > div.mmp-player div .entity__info__media span {
    color: #FFFFFF !important;
    }
    ha-card > div.mmp-player .mmp-player__adds mmp-media-controls {
    padding-bottom: 10px !important;
    }

I’m sure there may be a better way to do some of it, but it’s working for me at least, and I hope maybe it’ll help someone else!

15 Likes

Hi all. I am struggling with CSS styling on cards. Using card-mod.js, I am trying to remove the padding between the three dividers in the custom: text-divider-row card. I have tried editing the actual javascript of the card, but I also do not know javascript and nothing seemed to work. I used the following yaml code on the card for card-mod also, which did not work:

      - type: entities
        #title: Doors
        style: |
          ha-card {
          }
          .card-content {
            padding: 0 0 0 0px;
            box-shadow: none;
            }
        show_header_toggle: false
        entities:
          - type: divider
          - type: 'custom:text-divider-row'
            text: Doors
          - type: divider
          - binary_sensor.east_sliding_door
          - binary_sensor.south_sliding_door

Here is what the card looks like with and without the above attempt to change it:

Capture

I would appreciate any assistance.
Thanks,

Rick

Hi @thomasloven
I’m trying to change the icon on the fold-entity-row.
It works well on Chrome.
Only the color and size of the icon changes on Safari.

Chrome

Safari

- type: entities
  style:
    .: |
    "#states div > fold-entity-row":
      $:
       "#head > ha-icon":
         $:
           svg > g: |
             path {
               d: path("M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z");
             }
    "#states div":
      fold-entity-row:
        $: |
         #head ha-icon {
           color: var(--google-green-500);
           height: 36px;
         }
  entities:
    - type: custom:fold-entity-row
      head:
        entity:

According to a quick google search, this method (which honestly seems more like a mistake than a feature) indeed only works for Chrome.

1 Like

hello @thomasloven
why my image does not appear

type: entities
style: |
  ha-card {
    --ha-card-background: radial-gradient(lightgray, green);
    box-shadow: none;
    background: radial-gradient(lightgray, green);
  }
  .card-content {
    padding: 0
  }
entities:
  - type: 'custom:miflora-card'
    title: "\U0001F33F Ficus Benjamina"
    cards:
      title: "\U0001F33F Ficus Benjamina"
      image: images/plants.jpg
      min_moisture: 20
      max_moisture: 60
      min_conductivity: 350
      max_conductivity: 2000
      min_temperature: 8
      max_temperature: 32
      min_brightness: 2500
      min_battery: 98
      max_brightness: 35000
    entities:
      - 'moisture:sensor.planta_moisture'
      - 'intensity:sensor.planta_light_intensity'
      - 'temperature:sensor.planta_temperature'

1st image: original
2nd image: modded with above code

1 Like

Hi @thomasloven
Is it possible to resize cards using Card-mod or do i need to use lovelace-card-modder instead?
can’t figure this out and its driving me crazy.

Many thanks

style: |
ha-card {
height: 1000px;
}
2 Likes

Thanks @thomasloven. Will give it a go later.
Many thanks