Newer Version Available
Using Custom Styles
Use the <apex:stylesheet> tag or static
HTML to include your own style sheet or styles.
For HTML tags, you can define inline CSS code, just like in a regular HTML
page.
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<apex:page>
18 <style type="text/css">
19 p { font-weight: bold; }
20 </style>
21
22 <p>This is some strong text!</p>
23</apex:page>This example references a style sheet that is defined as a static resource. First, create a style
sheet and upload it as a static resource named
customCSS.
1h1 { color: #f00; }
2p { background-color: #eec; }
3newLink { color: #f60; font-weight: bold; }Next, create a page that refers to this static
resource.
1<apex:page showHeader="false">
2 <apex:stylesheet value="{!$Resource.customCSS}" />
3 <h1>Testing Custom Stylesheets</h1>
4 <p>This text could go on forever...<br/><br/>
5 But it won't!</p>
6
7 <apex:outputLink value="http://www.salesforce.com" styleClass="newLink">
8 Click here to switch to www.salesforce.com
9 </apex:outputLink>
10</apex:page>
Visualforce components that produce HTML
have pass-through style and styleClass attributes. These attributes allow you
to use your own styles and style classes to control the look and feel of the resulting
HTML. For example, the following code sets the class of the <apex:outputText> and applies a
style.
1swfobject.registerObject("clippy.codeblock-4", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<apex:page>
18 <style type="text/css">
19 .italicText { font-style: italic; }
20 </style>
21 <apex:outputText styleClass="italicText" value="This is kind of fancy."/>
22</apex:page>To apply a style using a DOM ID, use CSS attribute selectors for the style definition. See Defining Styles for a Component’s DOM ID.
If you intend to use images in your style sheet, zip the images with the CSS file, and upload the
file as a single static resource. For example, suppose your CSS file has a line like the
following.
Combine
the entire images directory and the parent CSS
file into a single zip file. In this example, the zip file resource name is
myStyles.
1body { background-image: url("images/dots.gif") }1<apex:stylesheet value="{!URLFOR($Resource.myStyles, 'styles.css')}"/>