Convert CSS to JavaFx CSS - css

I have a web application and for that we have CSS. We are porting the UI to JavaFX and intend to style it exactly the same way as it there on the web application. I tried loading the CSS which is used in the web project for this, but the style does not get reflected.
After a bit of searching i figured out that Oracle has created something called JavaFX CSS which is similar to CSS but not exactly CSS.
What I wanted to find out: is there some easy way to convert my (web) CSS to JavaFX CSS?

some easy way to convert my (web) CSS to JavaFx CSS
There is no automated convertor for this task. I advise you to take a little bit of your CSS and try to manually convert it by hand.
You, may be able to use analysis tools such as the CSS Analyzer in SceneBuilder to help with this task.
Refer to the JavaFX CSS Reference whilst performing your conversion.
If you have specific issues on converting elements or attributes between your JavaFX and HTML css files, then post new questions regarding those conversion difficulties.
We are porting the UI to JavaFx and intend to style it exactly the same way as it there on the Web Application.
That's going to be a little tricky if you have a lot of CSS. JavaFX CSS is not the same as web based HTML css. JavaFX CSS files share a common syntactic format with HTML CSS, but all of the css attributes in JavaFX differ from those found in HTML CSS.
HTML CSS can specify layout properties to be rendered by an HTML rendering engine. The JavaFX layout and rendering engine works differently from HTML, so HTML CSS based layout specifiers won't have direct equivalents in any of JavaFX CSS, JavaFX code or FXML defined layout managers.
Still, JavaFX CSS is very flexible. Many things are similar to HTML css (like region background and color specifiers), so it is possible to convert the gist of the HTML CSS to JavaFX CSS with acceptable accuracy in a reasonable amount of time, provided you are pretty skilled in both CSS forms. Just don't expect your JavaFX application and your web application to look or behave exactly the same.
Oracle has created something call JavaFX CSS which is similar to CSS but not exactly CSS.
JavaFX CSS is really just CSS in terms of its syntax and file format. CSS as used in JavaFX follows all of the basic syntax and data types of W3C CSS.
W3C CSS is what you term in your question as plain CSS or (web) CSS. There are many extensions and proposed extensions to W3C CSS and many of these extensions aren't even well supported across major browsers.
Consider using WebView for some parts of your application
Rather than port your entire application from HTML to JavaFX, you may want to keep some of the application in HTML and port other parts of the application to JavaFX controls.
JavaFX includes a WebView component which can be easily embedded in a JavaFX application. WebView can accurately render HTML, and it can parse and understand W3C CSS. You could use some of your existing CSS and HTML to style and render parts of your JavaFX application.
Because JavaFX CSS and W3C CSS share a common file format, you could even place both JavaFX CSS styles and W3C CSS styles in the same CSS file and the JavaFX and WebView runtimes would be clever enough to apply the appropriate styles when rendering their specific components.
See Also
JavaFX CSS Reference Guide
Learning CSS (JavaFx style)

Related

Extent of CSS3 support in JavaFX

What is the extent of CSS3 support in JavaFX? According to documentation
JavaFX Cascading Style Sheets (CSS) is based on the W3C CSS version 2.1 [1] with some additions from current work on version 3 [2]
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#introscenegraph
Cannot find anything specific here.
1) However how much percentage of CSS3 is supported in JavaFX?
The CSS3 specification must have come along way since this was first mentioned in the JavaFX CSS specifiaction.
2) What from CSS3 is supported?
There is only one mention of CSS3 in the JavaFX CSS specification.
3) Is it possible to use SASS with JavaFX CSS?
4) What changes does Java 9 have in regards of CSS support?
Although this is a 2yo question, I will answer for the sake of people. There is so little information about JavaFX css and sass, so I hope this answer will be of a help to someone.
1+2) I don't know the exact percentage but my experience with CssFX shows that very little original css3 code got into my css files. Most of the attributes are CssFX ones. Furthermore, there are many css3 attributes that defined on some JavaFX component, but not on others. I suggest you just learn it while going.
3) Yes, it is possible, and I did it just now in my current project.
Sass is a powerful framework to use with css, but eventually, the sass compiles the sass/scss code to a regular css, which can be used in your JavaFX app. just use the CssFX attribute in the sass code instead of the standard css3 attributes.
I'm using eclipse, so I've downloaded LiClipse from the market, which lets me view my .scss files from within their eclipse built-in editor. Sometimes I use SublimeText instead because of its extra tools.
About the sass/scss to css compilation, as I'm working with Maven, I use the maven-sass-plugin (specifically this one) to compile my project's scss files every time that I run my application. In addition, I've added to my project a builder, which compiles my scss files every time that a scss file has been changed (Sass builder example)
4) This is a question about Java 9 css support, which is barely related to the main topic of this question - which is JavaFX css - and should be asked as another topic.

What is a CSS Authoring framework?

I were looking for a CSS Framework to help me built website, when I struck with Compass.
Now, while I understand what a CSS Framework is, I don't understand what's a CSS Authoring Framework.
Expecially, I don't understand if it "replaces" a CSS Framework (like blueprint) or you should use it with a CSS Framework.
I'm building a website using Ruby On Rails, and I use SASS but no CSS Frameworks at the moment. If anyone can point me in right direction after answering the question, it will be really appreciated.
Edit 1:
Also, which is the difference between a CSS Framework and a CSS Authoring Framework
A CSS Framework is (in most cases) a fixed set of basic CSS definitions.
f.e. it brings definitions for some classes which make a basic div-based HTML-layout usable for different screen-widths. (aka liquid layout)
A CSS Authoring Framework (in meaning of Compass) brings no fixed set of CSS definitions. In opposite to a standard CSS Framework, it helps to write CSS rules with various helpers - but you have to write almost every CSS definition by your own. Some examples for helpers: Compass helps you to fix some common browser issues (IE floats ..). And you can create CSS sprites from existing images with all the CSS definitions on the fly.
You can write your own CSS Framework with the help of a CSS Authoring Framework, or you can simple build on top of a existing CSS Framework.
CSS frameworks are pre-prepared libraries that are meant to allow for easier, more standards-compliant styling of web pages using the Cascading Style Sheets language.
Layout-grid-related CSS frameworks include Bootstrap, Blueprint, 960 grid, YUI CSS, and other grids.
Like programming and scripting language libraries, CSS frameworks are usually incorporated as external .css sheets referenced in the HTML .
They provide a number of ready-made options for designing and laying out the web page. While many of these frameworks have been published, some authors use them mostly for rapid prototyping, or for learning from, and prefer to 'handcraft' CSS that is appropriate to each published site without the design, maintenance and download overhead of having many unused features in the site's styling.
Somehow, CSS framework == CSS Authoring framework

What is a CSS framework?

Can anyone tell me about CSS frameworks, and how to use them?
From Wikipedia:
A CSS framework is a pre-prepared library that is meant to allow for easier, more standards-compliant styling of web pages using the Cascading Style Sheets language. Like programming and scripting language libraries, CSS frameworks are usually incorporated as external .css sheets referenced in the HTML . They provide a number of ready-made options for designing and laying out the web page. While many of these frameworks have been published, some authors use them mostly for rapid prototyping, or for learning from, and prefer to 'handcraft' CSS that is appropriate to each published site without the design, maintenance and download overhead of having many unused features in the site's styling.[29]
There is a lot of material on SO (which framework to use, whether to use one at all....)
CSS frameworks are just CSS files. They provide pre-written CSS that you apply to your HTML by using the class names defined by the framework in its CSS file.
Some frameworks are focused on one particular task, e.g. page layout. 960.gs is a good example of this.
Some frameworks are more extensive, and include pre-written CSS for typography, form layout, print styles etc. Blueprint is a good example of this.
Some frameworks also include reset styles, which attempt to reset all styles for all HTML elements to very neutral defaults. These are automatically applied to all HTML elements, so you don’t add classes to your HTML to apply them. A lot of them are based on Eric Meyer’s CSS reset.
CSS frameworks address some or all of the following aspects:
Browser reset. This brings all browsers back to the same baseline styles so that you don't get surprised by something rendering differently in different browsers.
Layouts. They can provide pre-prepared styles that allow you to achieve certain layouts in a simple way. These include columns and also grid layout techniques.
Design. Some provide colour schemes, font selections, typography (line spacings etc.) to quickly give your page an appealing design.
Important to realize that you can mix and match - as long as you're careful.
For instance I don't particularly like YUI's Grid framework (not flexible enough for what I need) - and I don't particularly like Blueprint's typography (because I don't understand what it's doing and I think it's trying to do too much).
So I'm using YUI CSS Reset with YUI Typography and Blueprint grids !
CSS framework is a "wrapper" for all the styles and layouts on your Mark-Up (HTML etc) pages.
An example would be: http://www.blueprintcss.org/
Predefined functionality that has been created intended to serve as a guide for building of something useful.
There different frameworks with different functionality often a (programming tools)layered structure indicating what kind of functionality can be built and how they would work.
CSS frameworks are pre-prepared libraries that are meant to allow for easier, more standards-compliant styling of web pages using the Cascading Style Sheets language.
For more info on how to use each framework, please consult the official documentation of that framework.
Examples of popular CSS frameworks :
960 Grid System
Blueprint
Bootstrap
Cardinal
Cascade Framework
Chopstick
Columnal
Emastic
Floatz
Fluidable
Foundation
Gumby Framework
Ink
Jaidee Framework
KNACSS
Kube
Kule CSS Lazy
Malo
Pure
Responsive Grid System
Semantic UI
Skeleton
uikit
Unsemantic
YAML
Yet Another CSS Grid System
YUI CSS grids
Zass

what is the difference between CSS Frameworks and CSS Grids

Please tell me the difference between CSS Frameworks and CSS Grids.
CSS Framework can also be CSS Grid Framework. CSS Grid Frameworks are used for building CSS Layout. There are some frameworks who have other purpose then building layouts, example Hartija http://code.google.com/p/hartija/ is build for web printing.
Also the word "Framework" or "CSS Framework" is not precisely defined, there is one part of the CSS Community who believes that CSS Framework can be only CSS Layout system and the other part refers to any CSS Library.
CSS Grid is specification (set of rules which browser has to follow and understand). It's like a language between you and browser.
CSS Framework is like a wrapper, which includes set of specification,like CSS Grids, Flexbox, CSS2/3 and so on, which provide additional features.
For example: build a layout by grid. CSS Frameworks have own syntax, but actually it's just syntax sugar, which uses CSS specification the the code anyway.

Using ClientBundle image resources in css urls

I'm building an application in GWT and have a skin from my graphic designer which I've plugged into the app using UIBinder and it works beautifully. Now I want to bundle all the images using ClientBundle.
Mayne of these images are used in the css file e.g.
.nav{background:url(nav_bg.jpg) left top repeat-x; height:27px; clear:both;}
Before this css I have defined a tag to include the bundle.
How can I change the css entry so that it uses an ImageResource from my ClientBundle? I guess I can do inline styles for all the html tags but that's horrible separation and a lot of extra work.
I have successfully used ImageResources in the html part of the uibinder file (e.g. in a ) but I cannot see how to do this in the css. I have even inlined the css in a block but I still don't see the correct way to do this.
Any suggestions?
ClientBundles can now be used to host CssResources as well.
These CssResources are CSS files with some extra functionality.
The docs of GWT describes what you need in the section about ImageSprites.
I ended up skipping GWT css and image bundling altogether. Instead I've had my carve done using a css sprited image block made by the design/carve team. This has these advantages.
1/ Much less css porting since I can plug the html directly into ui binder and use the css tags from the carve i.e. not using uibinder css. As long as the html structure matches the carve then this is a lot less work than migrating all the css into gwt css.
2/ It also allows me to use svn/diff when applying changes - this was not possible when using gwt css/image spriting.
3/ I can easily put the image/css files on a CDN since the load tags are in the host page and don't suffer from Same Origin restrictions. FYI : yes I know about the XS linker as another way to do this.
It stops being useful when the carve uses css for positioning and I want to use LayoutPanels but that's not too bad as long as I request that the layout css is separate from the style css.
So in the end I discovered that, when working with design/carve from a third party, it's much easier to avoid using gwt css/images but to reproduce the same benefits using traditional css spriting and minification. I hope this helps someone.

Resources