This document summarizes how the WebFX CLI consumes unified CSS files (named *-webfx@main.css and other *-webfx@*.css) and produces the two platform-specific stylesheets:
- Web output: plain web CSS tailored for the WebFX single-host strategy
- JavaFX output: translated CSS compatible with OpenJFX’s CSS engine
It is intended as a practical guideline for authors of unified CSS in WebFX.
- Input files: any CSS file whose name contains
webfx@(for example:app-webfx@main.css). These are included in BOTH web and JavaFX targets. - Output file name: the
@...suffix is stripped in the generated resources (e.g.,app-webfx@main.css→main.css). - File headers: the CLI prepends a comment header indicating the source path and module.
- Validation: unified CSS is validated against the v1 subset before translation. Validation severity can be controlled with the system property
-Dwebfx.css.validation=error|warn|ignore. - @font-face ordering (JavaFX only): any
@font-facerules are moved to the top of the file to work around an OpenJFX loading quirk.
Only the JavaFX output transforms selectors; the web output keeps your selectors as-is (except for property moves described later).
fx-<tag>type selectors map to JavaFX type selectors (examples):fx-text→Textfx-label→Labelfx-button→Button- In general,
fx-foo-bar→ the corresponding JavaFX class name if recognized. Otherwise left unchanged.
:root(web) →.root(JavaFX style class) in selector headers..pseudo-selected(web helper class) →:selected(JavaFX pseudo-class).
- JavaFX output:
- Property names declared as CSS custom properties are rewritten:
--name: value;→-name: value; - Usages are rewritten:
var(--name)orvar(--name, fallback)→-name - Standard
color:property is mapped:color: …;→-fx-text-fill: …;
- Property names declared as CSS custom properties are rewritten:
- Web output:
color:is rewritten to--fx-text-fill:to align with the default host rule (color: var(--fx-text-fill))- Other custom property declarations/usages remain standard web CSS.
JavaFX output converts and normalizes the background family:
- Property name mapping:
background-color→-fx-background-colorbackground-image→-fx-background-imagebackground-repeat→-fx-background-repeatbackground-position→-fx-background-positionbackground-size→-fx-background-size
- Shorthand expansion:
background: …;is expanded into the longhands above, including layered backgrounds separated by commas. repeat-x/repeat-yare mapped torepeat no-repeat/no-repeat repeat.linear-gradient(to top|right|bottom|left|… , …)is converted to the JavaFX angle form.border-radiusis duplicated to-fx-background-radiusso the background clips as expected.
Web output keeps background properties as-is, with one addition:
border-radius: …;is duplicated to--fx-background-radius: …;to support clipping behavior in WebFX.
-
JavaFX output:
- Property name mapping:
border-style→-fx-border-styleborder-color→-fx-border-colorborder-width→-fx-border-widthborder-radius→-fx-border-radius
- Shorthand expansion:
border: <width> <style> <color>;is expanded into-fx-border-width,-fx-border-style,-fx-border-color. - Per-side shorthands are expanded:
border-top|right|bottom|left: …. - Per-side longhands are mapped:
border-*-width|style|color→-fx-border-*-width|style|color.
- Property name mapping:
-
Web output (single-host strategy):
- All border-related declarations are moved from the original selector to its
:beforepseudo-element. Other declarations remain on the original selector. - Example transformation:
/* input */ .card { border: 1px solid #ccc; background: white; } /* web output */ .card { background: white; } .card:before { border: 1px solid #ccc; }
- The WebFX runtime styles the single host so that
:beforevisually behaves like the element border.
- All border-related declarations are moved from the original selector to its
- JavaFX output maps common typographic properties:
font-family→-fx-font-familyfont-size→-fx-font-size(px values become unitless numbers as expected by JavaFX)font-weight→-fx-font-weight(numeric weights are normalized tonormal/boldconservatively)font-style→-fx-font-style(obliquebecomesitalic)text-align→-fx-text-alignmentopacity→-fx-opacity- The
font: …shorthand is expanded into the mapped longhands.
Web output keeps font declarations unchanged (standard web CSS).
stroke→-fx-strokestroke-width→-fx-stroke-widthstroke-linecap→-fx-stroke-line-capstroke-linejoin→-fx-stroke-line-joinfill→-fx-fill
cursor→-fx-cursor- Keyword mapping:
pointer→handgrab→open-handgrabbing→closed-handew-resize→h-resize,ns-resize→v-resizeno-drop/not-allowed→disappear
url(...)cursors are not supported by JavaFX. The CLI emits a warning comment and falls back todefault.
box-shadow: offset-x offset-y blur [spread] color;is translated to a JavaFX-fx-effect: dropshadow(...)approximation.- Current v1 focuses on a single non-inset shadow. Offsets and radii are adapted to JavaFX parameters. Complex cases may be approximated.
To help adoption, the translator inserts inline comments where behavior may differ:
- Use of unsupported shorthands (e.g., an unexpanded
background:) will receive a warning telling you to use longhands. - Any leftover per-side border constructs that could not be mapped will receive a warning.
-fx-cursor: url(...)is warned and replaced with a safe fallback.
- Prefer longhands in the v1 subset; when you use
background:orborder:shorthands, ensure they fit the supported patterns. - For text color, set
color:in unified CSS; it will become--fx-text-fill:on web and-fx-text-fill:on JavaFX. - When you use
border-radius, you do not need to set a background radius: the CLI duplicates it (--fx-background-radiuson web,-fx-background-radiuson JavaFX). - If you need element-type selectors for JavaFX, use the
fx-prefix (fx-label,fx-button, …). On the web, keep using normal HTML selectors. - If you use
@font-face, keep them in the unified CSS; the CLI moves them to the top for JavaFX.
Unified CSS (input):
:root { --brand: #246; }
fx-label.title {
color: var(--brand);
font: 600 14px/1.2 Roboto, sans-serif;
border: 1px solid #246;
border-radius: 8px;
background: linear-gradient(to bottom, #fff, #f7f9ff);
cursor: pointer;
}Web output (key differences highlighted):
:root { --brand: #246; }
fx-label.title {
--fx-text-fill: var(--brand);
font: 600 14px/1.2 Roboto, sans-serif;
border-radius: 8px;
--fx-background-radius: 8px;
background: linear-gradient(to bottom, #fff, #f7f9ff);
cursor: pointer;
}
fx-label.title:before {
border: 1px solid #246;
}JavaFX output (translated):
.root { -fx-some-global: something; } /* example of :root → .root when applicable */
Label.title {
-fx-text-fill: -brand;
-fx-font-weight: bold; /* numeric 600 normalized */
-fx-font-size: 14; /* px → unitless */
-fx-font-family: Roboto, sans-serif;
-fx-border-width: 1px;
-fx-border-style: solid;
-fx-border-color: #246;
-fx-border-radius: 8px;
-fx-background-radius: 8px;
-fx-background-image: linear-gradient(180deg, #fff, #f7f9ff);
-fx-cursor: hand; /* pointer → hand */
}This reflects the main v1 behaviors. Future versions may broaden the supported subset and reduce approximations.