[英]JavaFX CSS: How to inherit background color from other CSS settings?
I have a CSS file to set styles in JavaFX TabPane
and Tab
. 我有一个CSS文件来设置JavaFX TabPane
和Tab
样式。
Is there a way to set the TabPane
's background color and inherit Tab
background colors? 有没有办法设置TabPane
的背景颜色并继承Tab
背景颜色?
If I set the tab-content-area
background color, can I pick this up for the tab without having specifically nominate the color again? 如果我设置了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;
}
You can set the background of the Tab
transparent
or inherit
: 您可以将Tab
的背景设置为transparent
或inherit
:
.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;
}
You can check the CSS structure for TabPane
here . 您可以在此处检查TabPane
的CSS结构。
To learn more about named colors in JavaFX please refere to this section . 要了解有关JavaFX中命名颜色的更多信息,请参阅本节 。
Documentation of inherit
can be found here . inherit
文档可以在这里找到。
I did a bit more digging and found the answer to the question Declaring Variable In JavaFX CSS File allowed me to create a solution that works good enough for what I need. 我做了一些挖掘,并找到了问题的答案在JavaFX CSS文件中声明变量允许我创建一个足以满足我需要的解决方案。
My css now looks like this: 我的css现在看起来像这样:
* {
-fx-my-global-color:#d9d9d9;
}
.tab-content-area
{
-fx-background-color: -fx-my-global-color;
}
.tab:selected
{
-fx-background-color : -fx-my-global-color;
-fx-background-insets: 0, 1 1 0 1;
-fx-background-radius: 5 5 0 0, 4 4 0 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.