[英]JavaFX CSS: How to inherit background color from other CSS settings?
我有一個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
的背景設置為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;
}
您可以在此處檢查TabPane
的CSS結構。
要了解有關JavaFX中命名顏色的更多信息,請參閱本節 。
inherit
文檔可以在這里找到。
我做了一些挖掘,並找到了問題的答案在JavaFX CSS文件中聲明變量允許我創建一個足以滿足我需要的解決方案。
我的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.