Using Custom Styles

If you don’t want a page to have the Salesforce look and feel, specify false for the showHeader attribute on the <apex:page> tag, and then use the <apex:stylesheet> tag or HTML to include your own stylesheet and body.

For HTML tags , you can define inline CSS code just like in a regular HTML page:
    <style type="text/css">
        p { font-weight: bold; }

    <p>This is some strong text!</p>
The following example shows how to reference a stylesheet that is defined as a static resource. First, create a stylesheet like the one below and upload it as a static resource named customCSS:
h1 { color: #f00; }
p { background-color: #eec; }
newLink { color: #f60; font-weight: bold; }
Next, create a page that refers to this static resource:
<apex:page showHeader="false">
    <apex:stylesheet value="{!$Resource.customCSS}" />
    <h1>Testing Custom Stylesheets</h1>
    <p>This text could go on forever...<br/><br/>
       But it won't!</p>

    <apex:outputLink value="" styleClass="newLink"> Click here to switch to </apex:outputLink> </apex:page>
To shrink the size of your page, you can prevent the standard Salesforce stylesheets from loading by setting the standardStylesheets attribute on the <apex:page> component to false:
<apex:page standardStylesheets="false">
    <!-- page content here -->
Note that if you don’t load these style sheets, components that require Salesforce CSS might not display correctly, and their styling may change between releases.
All Visualforce components that produce HTML have pass-through style and styleClass attributes. They allow you to use your own styles and style classes to control the look and feel of any HTML tag. For example, the following code sets the class of the <apex:outputText> and applies a style:
    <style type="text/css">
        .italicText { font-style: italic; }
    <apex:outputText styleClass="italicText" value="This is kind of fancy."/>
If you want to apply a style using a DOM ID, you must use CSS attribute selectors for the style definition. Attribute selectors rely on the definition of an attribute, rather than an HTML tag, to apply a CSS style. You can set the id value on any Visualforce component; however, that id is sometimes preprended with the id of parent components. For instance, the id of the following code is j_id0:myId:
    <apex:outputText id="myId" value="This is less fancy."/>
Your CSS should take this into consideration by using an attribute selector:
    <style type="text/css">
        [id*=myId] { font-weight: bold; }
    <apex:outputText id="myId" value="This is way fancy !"/>
If you intend to use images in your stylesheet, zip the images with the CSS file and upload it as a single static resource. For example, if your CSS file has a line like the following:
body { background-image: url("images/dots.gif") }
Add the entire images directory and the parent CSS file into a single zip file. For example, if the zip file resource name is myStyles, refer to it like this:
<apex:stylesheet value="{!URLFOR($Resource.myStyles, 'styles.css')}"/>
If a stylesheet has an empty string in a url value, you won’t be able to render that page as a PDF. For example, the style rule body { background-image: url(""); } will prevent any page that includes it from being rendered as a PDF.
© Copyright 2000–2015, inc. All rights reserved.
Various trademarks held by their respective owners.