this问题似乎有些重复,但它无效。
存在两个扩展
HBox
并且有一个TextField
元素的类。我在每个类上添加StyleClass
,如下所示:
//for one class
getStyleClass().add("search-box");
//for the other class
getStyleClass().add("libraries-search-box");
所以我修改了
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;
....
}
我想替换重复的代码,我尝试:
.search-box , .libraries-search-box .text-field {
-fx-background-color: white;
-fx-background-insets:3.0;
-fx-background-radius: 5.0;
...//
}
但它只适用于' .libraries-search-box
'。我如何才能让两者都有效?
答案 0 :(得分: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;
...//
}
确实.search-box , .libraries-search-box .text-field
被视为.search-box
或.libraries-search-box .text-field
而不是.search-box .text-field
或.libraries-search-box .text-field
。
答案 1 :(得分:1)
正确的格式是:
.search-box .text-field, .libraries-search-box .text-field {
-fx-background-color: white;
-fx-background-insets:3.0;
-fx-background-radius: 5.0;
...//
}
在您的示例中,您为.search-box
和.libraries-search-box .text-field
类选择器定义了CSS属性。