custom-cards / stack-in-card

🛠 group multiple cards into one card without the borders
MIT License
262 stars 24 forks source link

'keep: margin: false' is not respected for inserted stack #34

Open ildar170975 opened 2 years ago

ildar170975 commented 2 years ago

Checklist:

Release with the issue: 0.2.0

Last working release (if known):

Browser and Operating System: Chrome, Win10x64

Description of problem:

If the 'keep: margin: false' is set then the margin between card is supposed to be 0. It works for two Entities cards:

  - type: custom:stack-in-card
    mode: vertical
    keep:
      background: true
      box_shadow: false
      margin: false
      outer_padding: false
      border_radius: false
    cards:
     - type: entities
       entities:
         - sun.sun
       card_mod:
         style: |
           ha-card {
             background-color: red;
           }
     - type: entities
       entities:
         - sun.sun
       card_mod:
         style: |
           ha-card {
             background-color: green;
           }

image

But if the 2nd card is stack-in-card, then the margin is present anyway - look at the margin-top:

  - type: custom:stack-in-card
    mode: vertical
    keep:
      background: true
      box_shadow: false
      margin: false
      outer_padding: false
      border_radius: false
    cards:
     - type: entities
       entities:
         - sun.sun
       card_mod:
         style: |
           ha-card {
             background-color: red;
           }
     - type: custom:stack-in-card
       mode: horizontal
       keep:
         background: true
         box_shadow: false
         margin: false
         outer_padding: false
         border_radius: false
       cards:
         - type: entities
           entities:
             - sun.sun
           card_mod:
             style: |
               ha-card {
                 background-color: red;
               }
         - type: entities
           entities:
             - sun.sun
           card_mod:
             style: |
               ha-card {
                 background-color: green;
               }

image

image

Javascript errors shown in the web inspector (if applicable): no

Additional information:

ildar170975 commented 2 years ago

And same for border_radius: false - it is clearly visible if you specify margin: true: image

ildar170975 commented 2 years ago

Probably same reason as here: https://github.com/custom-cards/stack-in-card/issues/20

ildar170975 commented 2 years ago

Seems that after 2021.12 functionality of "keep: margin: xxxx" gives erratic results if one stack includes another stack.

BadgerLoaf commented 1 year ago

I am seeing this problem too, where I have two horizontal stacks contained within a vertical stack.

I see this issue been open for a long time, is there a workaround or an update on the issue?

Thanks for your help!

ildar170975 commented 1 year ago

is there a workaround or an update on the issue?

Only by card-mod. A required code depends on a particular case.

BadgerLoaf commented 1 year ago

Thanks @ildar170975, I thought that might be the case.

I've actually started trying to fix mine using card-mod, as I have identified the issue in my case. Though am struggling with my skill (or lack of it!) to get the code right.

Have asked for help from the community here https://community.home-assistant.io/t/card-mod-add-css-styles-to-any-lovelace-card/120744/3799, hoping someone will be able to point me in the right direction.

Don't suppose you have any ideas?

ildar170975 commented 1 year ago

@BadgerLoaf The post you mentioned does not seem to me related to the problem. Could you re-ask your question again in that thread?

BadgerLoaf commented 1 year ago

Sorry @ildar170975 if I have misunderstood something, but the issue I'm seeing is where I have two horizontal stacks within a vertical stack (using custom:stack-in-card) and this causes a gap between the two horizontal cards.

Looking at the inspect code below, I have identified that I need to replace display: flex with display: block in the #root level highlighted below. If I change this within the inspect view, it fixes the issue. Screenshot 2022-11-04 at 16 50 25

Is this not the same issue you were seeing? Apologies for highjacking the thread if not.

ildar170975 commented 1 year ago

My issue can be seen here: изображение

There is a gap between 1st top card and the 2nd bottom card (which is a horiz stack). And this gap only occurs when the 2nd card is a stack. So I have to remove this margin manually. And I do it just by explicitly defining zero margins, not by changing a display property.

BadgerLoaf commented 1 year ago

Thanks @ildar170975.

I believe we are seeing the same issue (having a horizontal stack inside a vertical one).... though sounds like you have found an easier way to get around it, than my idea of changing that display property.

Would you mind sharing your code on how you changed to the margin to get around the issue?

BadgerLoaf commented 1 year ago

Hi @ildar170975 - Would you mind sharing your code as to how you removed this border? Thanks for your help!

ildar170975 commented 1 year ago

how you removed this border?

Sorry, I do not understand. You are talking about a border - but this issue and my picture above are about a margin. I have a solution for a margin only. As for borders - I just killed them on a theme level, do not use borders at all.

BadgerLoaf commented 1 year ago

@ildar170975 Apologies, you are right, it's a margin issue, not the border. I didn't use the correct words.

Like you I am seeing the margin of 4px... Screenshot 2022-11-16 at 15 49 06

What was your solution to remove the offending margin?

Thanks again!

ildar170975 commented 1 year ago

Seems that stack-in-card is abandoned by its author and have to be fixed by card-mod. This became worse after 2022.11.

W/o card-mod fix:

type: custom:stack-in-card
mode: vertical
title: title
keep:
  margin: false
  border: true
cards:
  - type: entities
    entities:
      - sun.sun
  - type: entities
    entities:
      - sun.sun
  - type: custom:stack-in-card
    mode: horizontal
    title: title
    keep:
      margin: true
      border: true
    cards:
      - type: entities
        entities:
          - sun.sun
      - type: entities
        entities:
          - sun.sun

image

With card-mod fix:

type: custom:stack-in-card
mode: vertical
title: title
keep:
  margin: false
  border: true
card_mod:
  style:
    hui-vertical-stack-card $: |
      div#root > * {
        margin: 0px !important;
      }
cards:
  - type: entities
    entities:
      - sun.sun
  - type: entities
    entities:
      - sun.sun
  - type: custom:stack-in-card
    mode: horizontal
    title: title
    keep:
      margin: true
      border: true
    cards:
      - type: entities
        entities:
          - sun.sun
      - type: entities
        entities:
          - sun.sun

image

Yes, there are still ugly round corners on the internal stack. Need to be also fixed by card-mod.

BadgerLoaf commented 1 year ago

@ildar170975 - Amazing, thank you! That card mod has worked and removed the gap caused by the margin.

Before: Screenshot 2022-11-18 at 14 56 25

After: Screenshot 2022-11-18 at 14 56 57

ildar170975 commented 1 year ago

Same problems with box-shadow & border.

wrouesnel commented 7 months ago

For anyone finding this, the solution for getting a clean no borders with this plugin and card mod is:

- type: custom:stack-in-card
  title: Air Conditioners
  mode: vertical
  card_mod:
    style:
      hui-vertical-stack-card $: |
        div#root > * {
          margin: 0px !important;
          --ha-card-border-width: 0;
        }
# elided the rest of the config...

Before: image

After: image

EDIT: Probably need to tweak the paddings to get it seamless, but you get the idea.