thomasloven / lovelace-card-mod

🔹 Add CSS styles to (almost) any lovelace card
MIT License
1.04k stars 169 forks source link

Issue styling Card Header #366

Closed Jab2870 closed 3 months ago

Jab2870 commented 3 months ago

My Home Assistant version: 2024.3.0

My lovelace configuration method (GUI or yaml): Mixture of both

What I am doing: Trying to style card-header

What I expected to happen: header to go green

What happened instead: Nothing

Minimal steps to reproduce:

The following is mostly taken from one of the test cases in the repo, although for a different card type

type: custom:hourly-weather
entity: weather.pirateweather
icons: true
show_precipitation_amounts: true
show_precipitation_probability: true
card_mod:
  style: |
    ha-card {
      color: red;
    }
    .card-header {
      color: green;
    }

image

I would expect the card-header here to be green.

Confirmation here that the card is using the standard "card-header" class which I would have thought the css selector would be selecting.

image

Error messages from the browser console: none relevant


By putting an X in the boxes ([]) below, I indicate that I:

ildar170975 commented 3 months ago

although for a different card type

And you believe that the code for card_X should work for card_Y...

Jab2870 commented 3 months ago

although for a different card type

And you believe that the code for card_X should work for card_Y...

Obviously not in all cases, no, although I had assumed that the card-header, an element that is used consistently across the majority of cards would be. Especially given the card-header is styled in most (maybe all) of the themes documented.

ildar170975 commented 3 months ago

In many cards a header is inside shadowRoot.

Especially given the card-header is styled in most (maybe all) of the themes documented.

Styling by changing a theme css variable is not same as styling by an explicitly defined DOM path & css attributes. Css vars may be defined on a ha-card level & sometimes it is quite sufficient.

Jab2870 commented 3 months ago

thanks for your points.

For what it is worth, I thought it might be to do with the shadow root so tried using the $ like so:

 style:
    .: |
      ha-card {
        color: red;
      }
    "ha-card $": |
      .card-header{
        color: blue;
      }

However, in order to avoid turning a bug report into a support ticket, is there somewhere you could point me towards in order to get help?

ildar170975 commented 3 months ago

To access shadowRoot inside ha-card, try this:

card_mod: 
  style:
    .: |
      ha-card {
       ...
      }
    $: |
      .card-header {
        ...
      }

in order to avoid turning a bug report into a support ticket, is there somewhere you could point me towards in order to get help?

The "issues" in this repo is mainly for bugs & FRs. For questions I suggest to use HA community (https://community.home-assistant.io/t/card-mod-add-css-styles-to-any-lovelace-card/120744).