function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rakesh SRakesh S 

Passing value from controller to css in salesforce

Hi All,

i have a custom page in that i want to display data in table. In that table, some data display with some color and it comes from controller.User-added image
in VF page, i put it like this 
<td style="background-color:{!w.EnglishColor}">
SocialColor came from controller. its working fine.

But now i want to use style class at <td>. and that color needs to come from controller. 
How should i acheave this problem using CSS. Because need CSS file that i put in static Resources.
Please help me any one using CSS only.

I appriciate your response.


Thank you.
Rakesh.S

 
AshlekhAshlekh
Hi,

You can define a style for a particular class and define this style in your CSS file like this
<style>
.Giveanyclassname{
difne style here
}
</style>

And than assign the class to your <td> tag.
 
<td class="{!w.EnglishColor}">

w.EnglishColor is should be hold the name of class for td tag.

-Thanks
Ashlekh Gera


 
Rakesh SRakesh S
Hi,
its not working. in style class, i want to define only backgroud color that is {!w.Englishcolor} and cames from controller.
<style type="text/css">
.colorExamData{
    background-color: "here i want to asign color that denied in controller"
    
}
how can i assign this styleclass to <td> tag. <td  styleClass="{!w.EnglishColor}">

Please anyone explain with some more explanation. 
 
karunakarreddy bade 8karunakarreddy bade 8
hi Rakesh


You can define a style for a particular class and define this style in your CSS file like this
syntax: css class 
<style>
.classname
{
define the style here
}
</style>

I think this documentation is worth reading through for a better understanding of adding the css class to controller

(http://salesforce.stackexchange.com/questions/25837/visualforce-adding-css-class-from-controller)

Thanks,
B.karunakar

 
Purva MittalPurva Mittal
you can use custom property to give dynamic styling . Refer this link :

https://lovesalesforceyes.blogspot.com/2020/07/two-ways-to-set-dynamic-style-in.html