Variables in CSS-Styles?

Forum to discuss the new web client version of Servoy.

Variables in CSS-Styles?

Postby HEKUCH » Thu Jan 05, 2017 4:51 pm

Hi,

Is this a way to work with Servoy-Variables in CSS-files? I found this example to work with CSS variables - but it dont work in NG-Client.

Define a css-variable
Code: Select all
:root {
  --main-bg-color: brown;
}


Use the css-variable
Code: Select all
.mytextbox
{
  background-color: var(--main-bg-color);
}


But this example is not what I want to do. My idea is to change some properties in the CSS file dynamically. I know there is a way to change the style dynamically. However, I can only access statically stored styles so far.

It would be best if I could the following:
Code: Select all
{
  background-color: %%scopes.globals.lnColor%% ;

}
Hendrick Kurland

DataBit GmbH
CH-9217 Neukirch an der Thur
HEKUCH
 
Posts: 13
Joined: Thu May 05, 2011 8:02 am

Re: Variables in CSS-Styles?

Postby paronne » Thu Jan 05, 2017 5:13 pm

Hi, form variables cannot be propagated into CSS.
What are you tryng to achieve here, color some elements conditionally depending on the value of a variable ?
If this is the case what you should do is to add/remove styleClass dinamically in your elements.
For example if a certain condition happens you can add a styleClass to the tabless panel of your main form : elements.tabless.addStyleClass("my-special-case");

You can then use CSS to change the look&feel of your elements.
Code: Select all
.svy-field {
  /* default color applied to all your fields */
   background-color: white;
}

.my-special-case .svy-field {
   /* This is applied to all the field nested inside the tabless panel when the class my-special-case has been added */
   background-color: yellow;
}


If instead what you are looking for is to use variables in CSS to keep changes in look&feel easy mantainable (when you change a color you change it everywhere is used) then LESS (http://lesscss.org/) fits your need. Using LESS you are allowed to use variables for your stylying and compile it into CSS. Note that in Servoy needs the compiled CSS.

Regards,
Paolo
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: Variables in CSS-Styles?

Postby HEKUCH » Fri Jan 06, 2017 1:00 pm

Hi Paolo,
Thank you for your answer .

I know that is not possible to be propagated form-variables into CSS. My quistion was general: Give it a way to defines "placeholder" (or functions/expression) in CSS.
In your example you defined a CSS-Class for the color white and yellow. Than I can switch at runtime. This is great! But I look for a way to define the Color outside of the CSS-File.

Redards,
Hendrick Kurland

DataBit GmbH
CH-9217 Neukirch an der Thur
HEKUCH
 
Posts: 13
Joined: Thu May 05, 2011 8:02 am

Re: Variables in CSS-Styles?

Postby jcompagner » Mon Jan 09, 2017 10:52 am

you can't switch those at runtime, servoy even has basis less support to compile less files to css but this is still a 1 time thing
Not a constant thing, why do you want to replace those place holders?
I guess per client when a client logs in??
You could potentially do that, just have a css file with your place holders in the media, then when a user logs in take that media, replace all the stuff you want
add the changed string as a media then use switch style sheet to switch the user to it.
But don't do this all the time, do it once as quickly as possible, and remember we can't cache anything in the browser for this media so it will download everytime,
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 1 guest