我在应用程序类中有这段代码
scene.getStylesheets().add(getClass().getResource(CONSTANTS.DESIGN_CSS.directory).toExternalForm());
和这个 CSS 文件
@CHARSET "UTF-8";
#mainList .list-cell {
-fx-background-color: null;
-fx-font-size: 24px;
-fx-text-fill: linear-gradient( from 0.0% 0.0% to 0.0% 50.0%, reflect, rgba(255,0,0,0.28) 0.0, rgba(102,243,255,0.58) 50.0, rgba(179,179,179,0.45) 70.0, rgba(179,179,179,0.45) 100.0);
}
#mainList .list-cell:hover {
-fx-text-fill:linear-gradient( from 0.0% 0.0% to 100.0% 100.0%, reflect, rgb(255,255,255) 0.0, rgb(255,255,77) 100.0);
}
#stoperButton .button {
-fx-background-color: linear-gradient( from 50.0% 100.0% to 100.0% 100.0%, rgb(0,0,0) 0.0, rgb(255,255,255) 100.0);
}
#stoperButton .button:hover {
-fx-background-color: #9ACD32;
}
在加载的第一个 Controller 中我可以很容易地做到这一点并且它有效:
listView.setId("mainList");
但这(在不同的 Controller 中)让我没有错误但没有效果:
buttSTOP.setId("stoperButton");
跟改变场景根有关系吗?
最佳答案
选择器
#stoperButton .button { ... }
匹配具有样式类“button”并且是 css id 为“stoperButton”的节点的后代的节点。
我觉得你想要的只是
#stoperButton {
-fx-background-color: linear-gradient( from 50.0% 100.0% to 100.0% 100.0%, rgb(0,0,0) 0.0, rgb(255,255,255) 100.0);
}
#stoperButton:hover {
-fx-background-color: #9ACD32;
}
关于css - 更改不同 Controller 中节点的 Id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28647266/