0

I have seen the recommended syntax as below -

.A:selected {
    -fx-background-color: green;
}

But that didnt work for me. I got it working using -

:selected .A {
    -fx-background-color: green;
}

Also, what is the syntax to apply the same style for multiple classes when selected? This worked for me, but wanted to know if there is a better/more concise syntax...

:selected .A, :selected .B, :selected .C {
    -fx-background-color: green;
}
Community
  • 1
  • 1
Darth Ninja
  • 1,049
  • 2
  • 11
  • 34
  • As you mentioned the first one is the recommended one. However I suspect the reason, why it does not work may be in how you apply the style to your node, so you would have to post some code there. – hotzst Nov 14 '15 at 08:20
  • 1
    `.A:selected` will match a node with style class `A` when it is selected, assuming it supports a `selected` pseudoclass. `:selected .A` will match a node with style class `A` that is a descendent in the scene graph of a node that is selected (and that supports the `selected` pseudoclass). So it basically just depends on what you are trying to apply style to. You can check the [documentation](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html) to see which pseudoclasses each node type supports. – James_D Nov 14 '15 at 14:45
  • Ah thanks, that is useful. What about applying the styles to multiple classes when they are selected? Is my syntax above correct? – Darth Ninja Nov 14 '15 at 15:11

0 Answers0