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

So basically this bit doesnā€™t work as the rest is kind of irrelevant

"#states div":
  mini-graph-card:
    $: |
      .card-content {
        padding: 0px;
      }

?

I donā€™t use the cards youā€™re using so cannot test but you need to open Inspect in your browser and check that inside your <div id=states there is another div with <mini-graph-card and inside its #shadow-root there is an element with class="card-content".
If you can see all of that, try to add in your browser padding: 0px; to that last thing and see if it works. If not, you might need to look around and see which element you need to apply the padding to to get the result and then adjust your card-mod selector :wink:
Thatā€™s how I do it.

1 Like

i have done but not wofking as before

when with my card-modder

cards:
  - card:
      entity: input_select.remote
      hold_action: none
      icon: hide
      name: TV
      tap_action:
        action: call-service
        service: input_select.set_options
        service_data:
          entity_id: input_select.remote
          options: TV
      type: entity-button
      style: |
        ha-card {
          border-radius: 20px;
          background-color: rgba(56, 60, 69, 1);
          box-shadow: 3px 3px rgba(0,0,0,0.4);
          outline: >-
            {% if(input_select.remote == "TV", "solid 3px red", "solid 3px rgba(255,125,125,1)");
          }
    type: 'custom:mod-card'
  - card:
      entity: input_select.remote
      hold_action: none
      icon: hide
      name: Mini
      tap_action:
        action: call-service
        service: input_select.set_options
        service_data:
          entity_id: input_select.remote
          options: Mini
      type: entity-button
    style:
      background-color: 'rgba(56, 60, 69, 1)'
      border: >-
        [[ if(input_select.remote == "Mini", "solid 3px red", "solid 3px
        rgba(255, 125, 125,1)") ]]
      border-radius: 20px
      box-shadow: '3px 3px rgba(0,0,0,0.4)'
    type: 'custom:card-modder'
  - card:
      entity: input_select.remote
      hold_action: none
      icon: hide
      name: Onkyo
      tap_action:
        action: call-service
        service: input_select.set_options
        service_data:
          entity_id: input_select.remote
          options: Onkyo
      type: entity-button
    style:
      background-color: 'rgba(56, 60, 69, 1)'
      border: >-
        [[ if(input_select.remote == "Onkyo", "solid 3px red", "solid 3px
        rgba(255, 125, 125,1)") ]]
      border-radius: 20px
      box-shadow: '3px 3px rgba(0,0,0,0.4)'
    type: 'custom:card-modder'
  - card:
      entity: input_select.remote
      hold_action: none
      icon: hide
      name: TataSky
      tap_action:
        action: call-service
        service: input_select.set_options
        service_data:
          entity_id: input_select.remote
          options: TataSky
      type: entity-button
    style:
      background-color: 'rgba(56, 60, 69, 1)'
      border: >-
        [[ if(input_select.remote == "TataSky", "solid 3px red", "solid 3px
        rgba(255, 125, 125,1)") ]]
      border-radius: 20px
      box-shadow: '3px 3px rgba(0,0,0,0.4)'
    type: 'custom:card-modder'
type: horizontal-stack

1

2

look at Mini and see the border with light red and when selected it goes dark red.
the changes i made is for TV but it doesnt have any border color
Please guide

I canā€™t find an class=ā€œcard-contentā€. I assume you repeated that from my code. Iā€™m still a noob and did not use the inspector before, therefore i assumed it should be .card-content. I tested again various things but nothing is working. Can you help me again with that picture?

Or is then

try

"#states div":
  mini-graph-card:
    $: |
      ha-card {
        padding: 0px;
      }

First: Please read this: https://community.home-assistant.io/t/card-mod-add-css-styles-to-any-lovelace-card/120744/453

Second: Please remove as much as possible from your examples.
I do not need to see all of your cards when only one is not working. Thatā€™s just a waste of my time.

Third: Your templates are messed up. Thereā€™s no end to your {% if. Card-mod uses jinja templates. See the readme.

Pro tip: Start simple. First make card-mod work (NOT MOD-CARD), then add templating.

Iā€™ve been getting good help elsewhere from @AhmadK with mod-card using display: none and I am using it to good effect.

However Iā€™m still having trouble using it with a conditional card.

I want to hide rows based on the state of an input_number and whilst the following works when the condition is true i.e. it hides the row, if the condition is false I get the big red error box.

  - type: custom:mod-card
    style: >
      {% set zone_count = states('input_number.irrigation_number_of_zones') %}
      {% if (zone_count | int) == 4 %}
        ha-card {display: none}
      {% else %}
        ha-card {display: unset}
      {% endif %}
    card:
      type: conditional
      conditions:
       --- and so on ---

Iā€™ve tried several variations on this theme.

image

Thanks for any help.

my method is an alternative to using conditional card, I can see no point in combining tbh.

Besides what Ahmad said, try configuring a card.

Yes! As I posted this that fact suddenly dawned on me.
I am adding to an existing config and for some reason completely missed the fact that this way I can get rid of the conditional altogetherā€¦

Letā€™s seeā€¦

The --- and so on --- was meant to be shorthand to prevent me needing to show the whole config. But yes, what @AhmadK saidā€¦

card:
  entity: input_select.remote
  hold_action: none
  icon: hide
  name: TV
  tap_action:
    action: call-service
    service: input_select.set_options
    service_data:
      entity_id: input_select.remote
      options: TV
  type: entity-button
style: |
  ha-card {
    background-color: 'rgba(56, 60, 69, 1)'
    border: >-
      [[ if(input_select.remote == "TV", "solid 3px red", "solid 3px rgba(255,125, 125,1)") ]]
    border-radius: 20px
    box-shadow: '3px 3px rgba(0,0,0,0.4)'
type: 'custom:mod-card'

dear this is my cofig turned from card-modder to mod-card
but the border doesnt show.
Please somebody guide thanks
and aslo how to use card-mod for the same

Great summary. Now try reading the rest of the reply.

I also updated the readme on github for you to make it even clearer what to do.

Need some help here. Iā€™m trying to hide the vertical lines in this weather card (stack into a vertical-stack and into a horizontal-stack).

Screen Shot 2020-04-02 at 9.15.31 AM

Hereā€™s what I see in dev tools:

Screen Shot 2020-04-02 at 9.21.13 AM Screen Shot 2020-04-02 at 9.14.58 AM

And hereā€™s the code:

style: |
  ha-card {
     overflow: hidden;
     width: 88.5%;
     height: 130px;
     padding-left: 0.5em;
  }
  .day {
     border-right: none;
  }

overflow, width and height change the style, but padding-left does not overwite the cardā€™s padding-left setting (it appears as strikethrough text in dev console). Same with border-right, it does not have any effect either. Only extra parameters seem to work, but canā€™t modify those set up in the original code. Any help would be great, thanks!

what does it say when you hover the pointer over it? try something like padding-left: 0.5em !important

1 Like

the !important flag made it work. Thanks so much!

1 Like

Anyone else having the issue that the following code affects all card of the same type?
Using this all ā€œcustom:vertical-stack-in-cardā€ gets a gray background. Any way of keeping the style to only affect the current card?

type: custom:vertical-stack-in-card
style: |
  ha-card {
    background: gray;
  }

This only happens with that particular card. The other card ā€œcustom:stack-in-cardā€ works but has other issuesā€¦

I might be wrong but what youā€™re styling is not a proper card, itā€™s a container for other cards. In Inspector can you see it has ha-card or background property at all?
What is most likely happening it applies this style to all ha-cards found recursively and there might be many inside your cards as LL cards use it often as a top level card (?)
So a solution is more precise targeting. It can be done but the cardsā€™s HTML structure should be analysed first and then you can try to construct a selector that will do the job.

Maybe try this instead? https://github.com/custom-cards/stack-in-card (itā€™s on hacs too)

Hi is it possible to remove the space between the different cards?

Would you mind helping me determine where I specify the configuration to remove the 8px padding shown here please?

image

I just canā€™t figure out what code to use and where, as seen with my attempt below. :slight_smile:

    - type: entities
      show_header_toggle: false
      style: |
        ha-card {
          padding: 0px;
          border-radius: 0px;
          height: 45px;
          box-shadow: none;
          background: none;
          width: 80px;
        }
        .card-content {
          padding: 0 0 0 0px;
        }
      entities:
        - entity: input_datetime.test
          style: 
            hui-generic-entity-row:
              $: |
                state-badge {
                  display: none;
                }
                div.padName {
                  display: none;
                }
                div.flex {
                  margin: 0px 0px 0px 0px;
                }
            paper-input-container:
              $: |
                #container {
                  padding: 0px;
                }

Hereā€™s more detail if it helps:
image