+ Start a Discussion
Rakesh ChattyRakesh Chatty 

i want to add color for <apex:outputField> label can someone suggest me how to change color to blue or red

i want to add color for <apex:outputField> label can someone suggest me how to change color to blue or red

apex:page standardController="contact"  recordSetVar="contacts" >
    <apex:pageBlock title="Contacts List" >
        <style>
        	.color{color:red;}
        </style>
        <apex:pageBlockSection title="contact" columns="2">
            <apex:repeat value="{!contacts}" var="a">
                <apex:outputField  value="{! a.lastName}" /> <br/>
                <apex:outputtext   value="{! a.lastName}" styleclass="color" /> <br/>
            </apex:repeat>
 </apex:pageBlock>
    
</apex:page>


 only for label text color should be red value should be black  

only Label should be red in color value should be in black as default.

 

thanks in adavance.

AnudeepAnudeep (Salesforce Developers) 

In general, we apply color like this
 
<apex:page standardController="Account">
    <font color="red">
        <apex:outputText value="{!Account.Name}"/>
    </font>
</apex:page>

You can assign CSS classes dynamically based on the value using the styleClass attribute as well

Try below code

<style>
.errorClass {
background-color: red;
}
.normalClass {
background-color: green;
}
</style>

<apex:pageBlock>
<apex:pageBlockTable value="{!testObjectList}" var="item">
<apex:column value="{!item.name}"
styleClass="{!IF(item.status__c == 'Critical','errorClass','normalClass')}"/>
<apex:column value="{!item.status__c}"
styleClass="{!IF(item.status__c == 'Critical','errorClass','normalClass')}"/>
</apex:pageBlockTable>
</apex:pageBlock>

Let me know if it helps