具有不同名称的JavaFX 2类具有相同的css代码

GOX*_*LUS 3 css java javafx

这个问题可能看似重复,但它无法正常工作.

存在两个扩展HBox并具有一个TextField元素的类.我在每个StyleClass类上添加了如下:

//for one class
 getStyleClass().add("search-box");

 //for the other class
 getStyleClass().add("libraries-search-box");
Run Code Online (Sandbox Code Playgroud)

所以我TextField用上面的css代码修改了他们的外观:

.search-box .text-field {
    -fx-background-color: white;    
    -fx-background-insets:3.0;
    -fx-background-radius: 5.0;   
     ..... 
}

.libraries-search-box .text-field {
    -fx-background-color: white;    
    -fx-background-insets:3.0;
    -fx-background-radius: 5.0;   
     ....
}
Run Code Online (Sandbox Code Playgroud)

我想替换重复的代码,我尝试:

.search-box , .libraries-search-box .text-field {
     -fx-background-color: white;   
    -fx-background-insets:3.0;
    -fx-background-radius: 5.0;
     ...//   
}
Run Code Online (Sandbox Code Playgroud)

但它只适用于' .libraries-search-box'.我如何才能让两者兼顾?

Nic*_*tto 5

你需要指定.text-field.search-box.text-field,作为下一个:

.search-box .text-field, .libraries-search-box .text-field {
     -fx-background-color: white;   
    -fx-background-insets:3.0;
    -fx-background-radius: 5.0;
     ...//   
}
Run Code Online (Sandbox Code Playgroud)

事实上,.search-box , .libraries-search-box .text-field被视为.search-box.libraries-search-box .text-field不作为.search-box .text-field.libraries-search-box .text-field作为你的期望.