Parent is hovered effects on children

  • ssssadsadasd-1321136035870015525

    ssssadsadasd

    3 months ago

    When a parent is hovered I want to change the background color of the children (but not of the parent itself). how can i do so? thanks
    1
  • ssssadsadasd-1321177249122357328

    ssssadsadasd

    3 months ago

    @Ben H any input on this? thanks
  • benjamin.h-1321178836074758265

    Ben H

    3 months ago

    You could make an isHovered variable. On the parent you can create mouseenter and mouseleave events to set the variable to true or false. Then on the child you can make an isHovered class that you bind to this variable. You can then style that class in the style panel.
  • ssssadsadasd-1321183439176728740

    ssssadsadasd

    3 months ago

    thanks 👍
  • lucasg-1321207723638919208

    Lucas G

    3 months ago

    You can achieve this with a <style> element as well using CSS (descendant combination)
  • Then no extra JavaScript is added to the page
  • xioteer-1324791636378521773

    Xioteer

    3 months ago

    But like this we would end up having css again in many different places, if am not completely wrong here?

    Because for this we would nee the style element placed somewhere to be able to work on that, while creating a variable and using a formula to activate the conditional style would keep it neat and tidy in the element's sidebar.

    Just found this on my search as I am facing the same issue
  • lucasg-1324794705195569172

    Lucas G

    3 months ago

    You would technically, yes.
  • I would keep the <style> element in the component itself, not elsewhere
  • Then it’s still tied to the component at least
  • lucasg-1324795323125858354

    Lucas G

    3 months ago

    The reason why I use a <style> element for this is that descendent selectors are not natively supported in the UI yet. The team is aware that they’re important but they’re not sure how to implement them in a nice way (the UI can quickly get huge if they add every CSS option)
  • xioteer-1324795417686183988

    Xioteer

    3 months ago

    you mean working with the attribute? or just drop the style element in the element itself?
  • lucasg-1324795442533367960

    Lucas G

    3 months ago

    And I do not want to add JS for this functionality
  • It is also easier to do with CSS anyways
  • lucasg-1324795668325466205

    Lucas G

    3 months ago

    Just add the element to the component itself
  • xioteer-1324795677326315551

    Xioteer

    3 months ago

    it does make sense. I just did it with the variable and adding 4 events just for a button icon change on hover seems massively overkill already
  • lucasg-1324795971733028896

    Lucas G

    3 months ago

    Yup. And if it’s a large app, adding extra JS is just not the way to go
  • CSS already handles it very well
  • xioteer-1324796021129084951

    Xioteer

    3 months ago

    You mean like this?
    1324796021112311960-image.png
  • lucasg-1324796054595440694

    Lucas G

    3 months ago

    Yup
  • xioteer-1324796175559163974

    Xioteer

    3 months ago

    wouldn't that cause many stylesheets?

    I have to admit I have not looked into the front-end yet how this is solved there then
  • many stylesheets if I did this several times*
  • lucasg-1324796360402407445

    Lucas G

    3 months ago

    It doesn’t add a global stylesheet, no. The style element lives in the DOM itself.
  • That said, multiple stylesheets are not a bad thing. It allows for modularity and loading the needed styles for the relevant page vs loading one large stylesheet for everything
  • xioteer-1324796614459523082

    Xioteer

    3 months ago

    so it's just a few text bits. Nice
  • lucasg-1324796671057727589

    Lucas G

    3 months ago

    Also, depending on how stylesheets are deployed, they can be cached
  • So multiple stylesheets are not necessarily a bad thing
  • xioteer-1324796812045058080

    Xioteer

    3 months ago

    Yeah, overall your approach seems a bit more lightweight, yes
  • lucasg-1324796964763861184

    Lucas G

    3 months ago

    This isn’t a stylesheet though just to clarify again lol. It is an inline style
  • xioteer-1324801653156876368

    Xioteer

    3 months ago

    Got it!
  • ssssadsadasd-1337441227787993150

    ssssadsadasd

    2 months ago

    @Lucas G any chance you can create a short implementation of this? I am stuck at the style element and dont understand the rest of the instructions. thanks
  • lucasg-1337442503447679069

    Lucas G

    2 months ago

    Examples are in the link
  • selector1 selector2 {
    /* property declarations */
    }
  • lucasg-1337443062569373899

    Lucas G

    2 months ago

    You can target states as well
  • selector1:hover selector2 {
    /* property declarations */
    }
  • ssssadsadasd-1337444225842675722

    ssssadsadasd

    2 months ago

    @Lucas G
    1. hmm but are these selectors inside the style element? If I have a container of type style and an svg or a text element as its children nothing is shown.
    2. is selector1 the style element?
  • lucasg-1337444353374818375

    Lucas G

    2 months ago

    A style element is simply to type in your CSS
  • ssssadsadasd-1337446686078931004

    ssssadsadasd

    2 months ago

    [here](https://toddle.dev/projects/moccasin_palpatine_chief_rook/branches/start/components/test2?leftpanel=design&canvas-width=800&canvas-height=800&rightpanel=attributes&selection=nodes.j1hlFTri9EGz8_5KUvwqW) I have two divs: one with id = separator1, and its child with id = separator2. I also have a style element with this css: selector1: hover selector2 {
    background-color: red;
    }:

    however, when I hover the color does not change. any idea why? thanks
  • lucasg-1337447684914806846

    Lucas G

    2 months ago

    Because you deleted the text element where you are supposed to type in the CSS
  • lucasg-1337449248391692351

    Lucas G

    2 months ago

    I fixed the CSS, were you able to see it?
  • ssssadsadasd-1337449272337236009

    ssssadsadasd

    2 months ago

    @Lucas G ah ok was not aware that the css for style was to go on the text element inside it (I added it on the style itself)

    nevertheless I still could not make it work 😦
    1337449272156753930-image.png
  • lucasg-1337449410136772751

    Lucas G

    2 months ago

    In CSS, you target ids with a #
  • You'll need to learn CSS syntax to use it
  • ssssadsadasd-1337449834113798175

    ssssadsadasd

    2 months ago

    ah now I made it work. yeah probably that is a good idea thanks

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.