SlideShare a Scribd company logo
Forcetree.comVisualforce CSS User Guide – Tips for CSS implementation in Visualforce Pages
VisualForce offers the ability to customize the look and feel of your VisualForce Pages. This guide is intended to cover the methodologies to be followed, and some best practices while implementing your own look and feel using custom styles.Do visit http://www.forcetree.com (my personal blog) for more examples and articles.Abstract
<apex:page>is the topmost tag in any VisualForce Page. This tag determines the styles to be used in your VisualForcepages. Let us start by creating a simple page with some basic styles. <apex:pageshowheader="false" sidebar="false">            <apex:form><h1> This is my first VisualForce Page! </h1> </apex:form></apex:page>Let’s walk through the code line by line <apex:pageshowheader="false" sidebar="false">When you set showheader=“false” the sidebar is also removed by default, however when you set sidebar=“false” the header will still display (obviously )The point to note here is when the header is removed Salesforce default stylesheets is no longer applied.Hence if you paste ordinary HTML code it will work perfectly.Getting Started
One step further…..Let’s modify the code and add a button..<apex:pageshowheader="false" sidebar="false">           <apex:form>                <h1> This is my first VisualForce Page! </h1>                  <apex:commandButton value="Done"></apex:commandButton>         </apex:form>     </apex:page>What did you notice? You’re right, the size of the text has reduced when you have not done anything to it.Why is this so?It is because we have used <apex:commandbutton> tag. This causes salesforce Standard stylesheets to be used. Not only this tag, but there are many others which cause a conflict. Hey!!, don’t worry there’s a way out there.Getting Started (cont..)
<apex:pageshowheader="false" sidebar="false" standardstylesheets=”false”>This will remove the salesforce standard stylesheets and you can now use your own styles without any worries. But, of course there are many more problems to be faced… Now lets add some color and effects…      <apex:pageshowheader="false" sidebar="false">	<apex:form>		<h1 style="text-align:center;color:blue;">		This is my first VisualForce Page! </h1>	</apex:form></apex:page>Output:This is called INLINE STYLING, it is called so because we have used style=” “ attribute inside the <h1> tagSTYLING….
When not to use INLINE STYLING????Suppose if you have ten <h1> tags in your page and you want all the text displayed in BLUE. Ideally you would have to add INLINE styles in all your ten <h1> tags.Toovercome this, we use <style> tag. We will modify our previous example using <style> tag.<apex:pageshowheader="false" sidebar="false"><style>  h1  {text-align:center;color:blue;  }</style><apex:form>   <marquee> <h1> This is my first VisualForce Page! </h1> </marquee>   <h1> This text is displayed without INLINE styles </h1></apex:form></apex:page>                                    OUTPUT:STYLING….
USING STYLE CLASS….How about a more complicated page with styleclass?. Adding many styles into a single holder is called a styleclass. You can then use the styleclass anywhere in your page<apex:pageshowheader="false" sidebar="false" standardcontroller="Account" standardstylesheets="false"><style>.red{ background-color:red;}.green{ background-color:green;}.blue{ background-color:blue;}</style>   <apex:form >   <h1 style="text-align:center;color:blue;"> This is my first VisualForce Page! </h1>   <apex:datatable value="{!Account.Contacts}" var="con" border="1" cellspacing="5" cellpadding="5" columnClasses="red,green,blue"><apex:columnheadervalue="Contact FirstName"> <apex:outputfieldvalue="{!con.FirstName}"/> </apex:column><apex:columnheadervalue="Contact LastName"> <apex:outputfieldvalue="{!con.LastName}"/> </apex:column><apex:columnheadervalue="Contact Name"> <apex:outputfield value="{!con.Title}"/></apex:column>   </apex:datatable>   </apex:form></apex:page>                                                         OUTPUT:
USING STYLE CLASS…. contIn the above code sample when you say columnclasses="red,green,blue" in <apex:datatable> tag it means that the styleclass "red" would be applied for the first column, "green" would be applied forthe second column and "blue“ would be applied for the third column. When you have a fourth column "red" styleclass would be applied again, because it works in a repetitive fashion. You can use as many classses as you need for any number of columns.
CSS with VisualforceCSS – stands for Cascading Style Sheets. It is a file which ends with the extension “.css” (Ex: mystyles.css)Why use CSS?Readability : Using a CSS makes your code more readable. It separates your style definitions from your Visualforce page.Reusability : You can use your CSS file across multiple visualforce pages, and whenever you need modifications to your styles changing the CSS file would change all your underlying Visualforce pages.Let us modify the previous example using   STYLECLASS   and achieve the same using CSS.Creating a CSS file:Step 1: Open Notepad, or any text editor.cont ….
CSS with Visualforce           (cont …..)Step 2: Paste the following code.red{ background-color:red;}.green{ background-color:green;}.blue{ background-color:blue;}Save this file as, “mystyle.css”Step3: Upload this file into Static Resources, name the resource as “mystyle”.
CSS with Visualforce           (cont …..)Step 2: Create a visualforce page with the following code<apex:pageshowheader="false" sidebar="false" standardcontroller="Account" standardstylesheets="false"><apex:stylesheet value="{!URLFOR($Resource.mystyle)}"/><apex:form >   <h1 style="text-align:center;color:blue;"> This is my first VisualForce Page! </h1>   <apex:datatable value="{!Account.Contacts}" var="con" border="1" cellspacing="5" cellpadding="5" columnClasses="red,green,blue"><apex:columnheadervalue="Contact FirstName"> <apex:outputfieldvalue="{!con.FirstName}"/> </apex:column><apex:columnheadervalue="Contact LastName"> <apex:outputfieldvalue="{!con.LastName}"/> </apex:column><apex:columnheadervalue="Contact Name"> <apex:outputfield value="{!con.Title}"/></apex:column>   </apex:datatable>   </apex:form></apex:page>The line in GREEN denotes the place where we actually reference our CSS file in our Visualforce Page
CSS FOLDER with VisualforceCSS Folder:When you download/buy CSS from an external vendor like http://www.freecsstemplates.org/, the CSS usually comes as a bunch of files and folders as shown below. This is because your CSS uses IMAGES, and some other files, all of which are placed into the respective folders. For  your CSS to work properly, you would need these folders.In such a case, create a ZIP file of all the files shown above. For Example, Just place all the files shown above into a folder called “stylefiles”. Make a ZIP file of this, and call it “stylefiles.zip”. Now, upload this ZIP file into Static Resources with the name “stylezip”. Now, we will need to reference this CSS into our Visualforce Page.
CSS FOLDER with VisualforceCreate a Visualforce Page with the following code.<apex:pageshowheader="false" sidebar="false" standardcontroller="Account" standardstylesheets="false"><apex:stylesheet value="{!URLFOR($Resource.stylezip ,'stylefiles/style.css')}"/></apex:page>Note: “stylefiles/style.css”. Here, stylefiles is the folder name within which you have the style.css file.  If you have the CSS within a different folder, you will have to specify the appropriate structure.

More Related Content

What's hot (15)

ODP
Creating Web Sites with HTML and CSS
BG Java EE Course
 
PPTX
Creating a webpage in html
Shrey Goswami
 
PPTX
Html css java script basics All about you need
Dipen Parmar
 
PPT
Css 2010
guest0f1e7f
 
PPT
Webpages And Dynamic Content
maycourse
 
PPTX
The Pragmatist's Approach to SharePoint Branding
Stu King
 
DOCX
Master page
Paneliya Prince
 
PPT
HTML & CSS Workshop Notes
Pamela Fox
 
PPTX
How To Write Beautiful Code
2C Development Group
 
PDF
Web Design Course: CSS lecture 5
Gheyath M. Othman
 
PPTX
David Weliver
Philip Taylor
 
DOCX
Tercer trabajo de drapi 02
Jhon Silva Penekita
 
PPTX
Introduction to HTML4
Collaboration Technologies
 
PDF
Introduction to HTML and CSS
Mario Hernandez
 
Creating Web Sites with HTML and CSS
BG Java EE Course
 
Creating a webpage in html
Shrey Goswami
 
Html css java script basics All about you need
Dipen Parmar
 
Css 2010
guest0f1e7f
 
Webpages And Dynamic Content
maycourse
 
The Pragmatist's Approach to SharePoint Branding
Stu King
 
Master page
Paneliya Prince
 
HTML & CSS Workshop Notes
Pamela Fox
 
How To Write Beautiful Code
2C Development Group
 
Web Design Course: CSS lecture 5
Gheyath M. Othman
 
David Weliver
Philip Taylor
 
Tercer trabajo de drapi 02
Jhon Silva Penekita
 
Introduction to HTML4
Collaboration Technologies
 
Introduction to HTML and CSS
Mario Hernandez
 

Viewers also liked (8)

DOCX
A research on- Sales force Project- documentation
Pasupathi Ganesan
 
PDF
Salesforce crm projects
Advanz Knowledge Systems P Ltd
 
PDF
Recruitment Application full SRS developed in Salesforce.com
Ravi Gupta
 
PDF
Angular-ifying Your Visualforce Pages
Salesforce Developers
 
DOCX
Interview questions
mallareddy0107
 
PDF
Salesforce course-training-material
sfdc232
 
PPTX
MVC - Introduction
Sudhakar Sharma
 
PPTX
Web api
Sudhakar Sharma
 
A research on- Sales force Project- documentation
Pasupathi Ganesan
 
Salesforce crm projects
Advanz Knowledge Systems P Ltd
 
Recruitment Application full SRS developed in Salesforce.com
Ravi Gupta
 
Angular-ifying Your Visualforce Pages
Salesforce Developers
 
Interview questions
mallareddy0107
 
Salesforce course-training-material
sfdc232
 
MVC - Introduction
Sudhakar Sharma
 
Ad

Similar to Visualforce css developer guide(by forcetree.com) (11)

PDF
Workbook vf
Godot Back
 
PDF
Visualforce Workbook
SLMaster
 
PPTX
Getting a Quick Start with Visualforce
Mohammed Safwat Abu Kwaik
 
PDF
Customizing sales force-interface
Amit Sharma
 
PPT
Vf ppt (1)
Preeti Mohanty
 
PDF
Customizing sales force-interface
Amit Sharma
 
PDF
Getting Started with Visualforce
Rati Sharma
 
PDF
Visualforce controllers
Amit Sharma
 
PPTX
SFDC UI - Advanced Visualforce
Sujit Kumar
 
PPTX
Webinar: Salesforce Customization using Visualforce and Lightning Component F...
APPSeCONNECT
 
PPTX
Introduction to visualforce
Rinku Saini
 
Workbook vf
Godot Back
 
Visualforce Workbook
SLMaster
 
Getting a Quick Start with Visualforce
Mohammed Safwat Abu Kwaik
 
Customizing sales force-interface
Amit Sharma
 
Vf ppt (1)
Preeti Mohanty
 
Customizing sales force-interface
Amit Sharma
 
Getting Started with Visualforce
Rati Sharma
 
Visualforce controllers
Amit Sharma
 
SFDC UI - Advanced Visualforce
Sujit Kumar
 
Webinar: Salesforce Customization using Visualforce and Lightning Component F...
APPSeCONNECT
 
Introduction to visualforce
Rinku Saini
 
Ad

Recently uploaded (20)

PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
 
PDF
NASA A Researcher’s Guide to International Space Station : Earth Observations
Dr. PANKAJ DHUSSA
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
NASA A Researcher’s Guide to International Space Station : Fundamental Physics
Dr. PANKAJ DHUSSA
 
PDF
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
PPTX
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
PPTX
Essential Content-centric Plugins for your Website
Laura Byrne
 
PPTX
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
 
PDF
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
Edge AI and Vision Alliance
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
 
NASA A Researcher’s Guide to International Space Station : Earth Observations
Dr. PANKAJ DHUSSA
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
NASA A Researcher’s Guide to International Space Station : Fundamental Physics
Dr. PANKAJ DHUSSA
 
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
Essential Content-centric Plugins for your Website
Laura Byrne
 
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
 
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
Edge AI and Vision Alliance
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 

Visualforce css developer guide(by forcetree.com)

  • 1. Forcetree.comVisualforce CSS User Guide – Tips for CSS implementation in Visualforce Pages
  • 2. VisualForce offers the ability to customize the look and feel of your VisualForce Pages. This guide is intended to cover the methodologies to be followed, and some best practices while implementing your own look and feel using custom styles.Do visit http://www.forcetree.com (my personal blog) for more examples and articles.Abstract
  • 3. <apex:page>is the topmost tag in any VisualForce Page. This tag determines the styles to be used in your VisualForcepages. Let us start by creating a simple page with some basic styles. <apex:pageshowheader="false" sidebar="false"> <apex:form><h1> This is my first VisualForce Page! </h1> </apex:form></apex:page>Let’s walk through the code line by line <apex:pageshowheader="false" sidebar="false">When you set showheader=“false” the sidebar is also removed by default, however when you set sidebar=“false” the header will still display (obviously )The point to note here is when the header is removed Salesforce default stylesheets is no longer applied.Hence if you paste ordinary HTML code it will work perfectly.Getting Started
  • 4. One step further…..Let’s modify the code and add a button..<apex:pageshowheader="false" sidebar="false"> <apex:form> <h1> This is my first VisualForce Page! </h1> <apex:commandButton value="Done"></apex:commandButton> </apex:form> </apex:page>What did you notice? You’re right, the size of the text has reduced when you have not done anything to it.Why is this so?It is because we have used <apex:commandbutton> tag. This causes salesforce Standard stylesheets to be used. Not only this tag, but there are many others which cause a conflict. Hey!!, don’t worry there’s a way out there.Getting Started (cont..)
  • 5. <apex:pageshowheader="false" sidebar="false" standardstylesheets=”false”>This will remove the salesforce standard stylesheets and you can now use your own styles without any worries. But, of course there are many more problems to be faced… Now lets add some color and effects… <apex:pageshowheader="false" sidebar="false"> <apex:form> <h1 style="text-align:center;color:blue;"> This is my first VisualForce Page! </h1> </apex:form></apex:page>Output:This is called INLINE STYLING, it is called so because we have used style=” “ attribute inside the <h1> tagSTYLING….
  • 6. When not to use INLINE STYLING????Suppose if you have ten <h1> tags in your page and you want all the text displayed in BLUE. Ideally you would have to add INLINE styles in all your ten <h1> tags.Toovercome this, we use <style> tag. We will modify our previous example using <style> tag.<apex:pageshowheader="false" sidebar="false"><style> h1 {text-align:center;color:blue; }</style><apex:form> <marquee> <h1> This is my first VisualForce Page! </h1> </marquee> <h1> This text is displayed without INLINE styles </h1></apex:form></apex:page> OUTPUT:STYLING….
  • 7. USING STYLE CLASS….How about a more complicated page with styleclass?. Adding many styles into a single holder is called a styleclass. You can then use the styleclass anywhere in your page<apex:pageshowheader="false" sidebar="false" standardcontroller="Account" standardstylesheets="false"><style>.red{ background-color:red;}.green{ background-color:green;}.blue{ background-color:blue;}</style> <apex:form > <h1 style="text-align:center;color:blue;"> This is my first VisualForce Page! </h1> <apex:datatable value="{!Account.Contacts}" var="con" border="1" cellspacing="5" cellpadding="5" columnClasses="red,green,blue"><apex:columnheadervalue="Contact FirstName"> <apex:outputfieldvalue="{!con.FirstName}"/> </apex:column><apex:columnheadervalue="Contact LastName"> <apex:outputfieldvalue="{!con.LastName}"/> </apex:column><apex:columnheadervalue="Contact Name"> <apex:outputfield value="{!con.Title}"/></apex:column> </apex:datatable> </apex:form></apex:page> OUTPUT:
  • 8. USING STYLE CLASS…. contIn the above code sample when you say columnclasses="red,green,blue" in <apex:datatable> tag it means that the styleclass "red" would be applied for the first column, "green" would be applied forthe second column and "blue“ would be applied for the third column. When you have a fourth column "red" styleclass would be applied again, because it works in a repetitive fashion. You can use as many classses as you need for any number of columns.
  • 9. CSS with VisualforceCSS – stands for Cascading Style Sheets. It is a file which ends with the extension “.css” (Ex: mystyles.css)Why use CSS?Readability : Using a CSS makes your code more readable. It separates your style definitions from your Visualforce page.Reusability : You can use your CSS file across multiple visualforce pages, and whenever you need modifications to your styles changing the CSS file would change all your underlying Visualforce pages.Let us modify the previous example using STYLECLASS and achieve the same using CSS.Creating a CSS file:Step 1: Open Notepad, or any text editor.cont ….
  • 10. CSS with Visualforce (cont …..)Step 2: Paste the following code.red{ background-color:red;}.green{ background-color:green;}.blue{ background-color:blue;}Save this file as, “mystyle.css”Step3: Upload this file into Static Resources, name the resource as “mystyle”.
  • 11. CSS with Visualforce (cont …..)Step 2: Create a visualforce page with the following code<apex:pageshowheader="false" sidebar="false" standardcontroller="Account" standardstylesheets="false"><apex:stylesheet value="{!URLFOR($Resource.mystyle)}"/><apex:form > <h1 style="text-align:center;color:blue;"> This is my first VisualForce Page! </h1> <apex:datatable value="{!Account.Contacts}" var="con" border="1" cellspacing="5" cellpadding="5" columnClasses="red,green,blue"><apex:columnheadervalue="Contact FirstName"> <apex:outputfieldvalue="{!con.FirstName}"/> </apex:column><apex:columnheadervalue="Contact LastName"> <apex:outputfieldvalue="{!con.LastName}"/> </apex:column><apex:columnheadervalue="Contact Name"> <apex:outputfield value="{!con.Title}"/></apex:column> </apex:datatable> </apex:form></apex:page>The line in GREEN denotes the place where we actually reference our CSS file in our Visualforce Page
  • 12. CSS FOLDER with VisualforceCSS Folder:When you download/buy CSS from an external vendor like http://www.freecsstemplates.org/, the CSS usually comes as a bunch of files and folders as shown below. This is because your CSS uses IMAGES, and some other files, all of which are placed into the respective folders. For your CSS to work properly, you would need these folders.In such a case, create a ZIP file of all the files shown above. For Example, Just place all the files shown above into a folder called “stylefiles”. Make a ZIP file of this, and call it “stylefiles.zip”. Now, upload this ZIP file into Static Resources with the name “stylezip”. Now, we will need to reference this CSS into our Visualforce Page.
  • 13. CSS FOLDER with VisualforceCreate a Visualforce Page with the following code.<apex:pageshowheader="false" sidebar="false" standardcontroller="Account" standardstylesheets="false"><apex:stylesheet value="{!URLFOR($Resource.stylezip ,'stylefiles/style.css')}"/></apex:page>Note: “stylefiles/style.css”. Here, stylefiles is the folder name within which you have the style.css file. If you have the CSS within a different folder, you will have to specify the appropriate structure.