How can I change a child element CSS when the pare...
# compose-web
m
How can I change a child element CSS when the parent is hovered with Compose Web's Style DSL? In CSS, it is like this
Copy code
.parent:hover .child { /* rules here */ }
However I'm not able to figure out how to represent that in the Style DSL 😞
a
Copy code
object MyStyleSheet : StyleSheet() {
   init {
     ".parent:hover .child" {
        /* rules here */
     }
   }
}
or
Copy code
object MyStyleSheet : StyleSheet() {
   val parent by style {}
   val child by style {
       parent + ":hover " + self {
           /* rules here */
       }
   }
}
m
The second snippet doesn't seem to be working, it is applying the rules to the child even if I'm not hovering the parent 😭 However the first snippet works without any issues 🙂
a
@MrPowerGamerBR, can you paste here how exactly looks snippet which doesn’t work for you? I need to check it. It should work
m
@Akif Abasov [JB]
Copy code
object TestStylesheet : StyleSheet() {
    val parent by style {
        backgroundColor(Color.red)
    }

    val child by style {
        fontSize(16.px)

        parent + ":hover " + self {
            /* rules here */
            fontSize(32.px)
        }
    }
}
message has been deleted
a
thanks, i’ll check it. It looks like a bug.
could you try?
Copy code
(parent + ":hover " + self) {
            /* rules here */
            fontSize(32.px)
        }
m
Also doesn't work: Only the "fontSize(16.px)" rule is applied
message has been deleted
a
oh… i think i know what’s wrong. parent is just “parent”, while it should be “.parent” Try
Copy code
className(parent) + ":hover " + self
m
😭
className seems to return a CSSClass object, so it fails to + with a string
a
yeah, it’s signature problem. I’ll fix this
problem is here. Anyway thank you for feedback. I’ll fix this stuff
m
Thanks! 🙂
t
I'm not sure why but I tried
Copy code
init {
    "$parent:hover $child" {
        ...
    }
}
without succeed
As I check with the console log, the key "parent:hover child" is in the rule list but the style is not applied. With single selector like "p", it works well