我有一个 CSS 文件来在 JavaFX TabPane
和 Tab
中设置样式。
有没有办法设置TabPane
的背景颜色并继承Tab
背景颜色?
如果我设置了 tab-content-area
背景颜色,我可以为选项卡选择该背景颜色而无需再次专门指定颜色吗?
.tab-content-area
{
-fx-background-color: #d9d9d9; /* I want to apply this color to tab background */
}
.tab:selected
{
-fx-background-color : -fx-something; <?? what do i put here??>
-fx-background-insets: 0, 1 1 0 1;
-fx-background-radius: 5 5 0 0, 4 4 0 0;
}
最佳答案
您可以设置Tab
的背景透明
或继承
:
.tab-content-area {
-fx-background-color: #d9d9d9; /* I want to apply this color to tab background */
}
.tab:selected {
-fx-background-color : transparent; /* Or: -fx-background-color : inherit;*/
-fx-background-insets: 0, 1 1 0 1;
-fx-background-radius: 5 5 0 0, 4 4 0 0;
}
您可以检查 TabPane
here 的 CSS 结构.
要了解有关 JavaFX 中命名颜色的更多信息,请参阅 this section .
可以找到inherit
的文档here .
关于JavaFX CSS : How to inherit background color from other CSS settings?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37385558/