Declaring Variable In JavaFX CSS File

前端 未结 5 1036
悲&欢浪女
悲&欢浪女 2020-12-08 20:10

I\'ve been inspecting the \"caspian.css\" distributed by Oracle in the JavaFX runtime library, and I see they have declared some color values as variables. Eg:



        
5条回答
  •  执念已碎
    2020-12-08 20:54

    I aways separate my css code.

    I create a importer file named all.css with code bellow:

    @import url("Root.css");
    @import url("Base.css");
    ...
    

    In Root.css file, i set the variables:

    .root {
        -fx-color1: #FFFF00;
        -fx-color2: rgb(255,255,0);
        -fx-color3: rgba(255,255,0, 0.5);
    }
    

    Now, i can call variables in all bellow of imported code after import(Root.css). In Base.css for example.

    .bg-yellow1 {
        -fx-background-color: -fx-color1;
    }
    

    That's it!

提交回复
热议问题