JavaFX CSS : How to inherit background color from other CSS settings?

标签 java css javafx background-color

我有一个 CSS 文件来在 JavaFX TabPaneTab 中设置样式。

有没有办法设置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/

相关文章:

数字的Java正则表达式以代码开头

html - 将 DIV 与绝对定位的子项水平对齐

css - 字体不会通过 webpack 加载

java - JavaFX:基于属性的实体与基于属性的包装器

java - 使用 java jxl 在现有工作簿中添加新工作表

java - 了解八卦协议(protocol)

java - Maven:缺少所需的 java 项目

jquery - 如何检测div中的css属性

应用程序启动方法中的Javafx错误异常未指定 Controller

JavaFX 线程卡住 GUI