Working With External Cascading Style Sheets
- Edit an existing CSS, adding or modifying rules. For example, you can add generic classes to an existing style sheet to format your report's components. When you edit an existing CSS, the next time someone displays the report on a browser it reflects those changes without their having to rerun the report (provided an earlier version was not cached on the browser, in which case he or she has to refresh the view to see the edited version).
- Create your own Cascading Style Sheet to format reports.
Applying CSS Styles
You can apply external Cascading Style Sheet (CSS) formatting to:
- A report component (for example, to make a column italic). Assign Cascading Style Sheet classes to report components using FOCUS StyleSheet CLASS attributes. When formatting tabular or free‑form reports, you can format any report component by assigning CSS classes. To center headings or footings, use the CENTER option of the HEADING or FOOTING command, rather than doing this in a style sheet.
- An entire report (for example, to make an entire report italic). You can specify this formatting in an external CSS rule for the BODY or TD elements. You do not need a rule for a class of an element, nor do you need a FOCUS StyleSheet declaration when formatting an entire report with this approach.
When using an external Cascading Style Sheet to format a report, it is recommended not to use a FOCUS StyleSheet to specify the report's formatting unless you also generate an internal Cascading Style Sheet.
Syntax: How to Use the CLASS Attribute to Apply CSS Formatting
To apply an external Cascading Style Sheet (CSS) class to a report component, use the following syntax in a FOCUS StyleSheet declaration.
TYPE = type, [subtype,] CLASS = classname, [when,] [link,] $
where:
type
Identifies the report component to which you are applying the class's formatting. For tabular and free‑form reports, it can be any component.
Each report component can be formatted by one class. If you specify several classes for a report component:
-
Classes in declarations with conditional formatting are evaluated first. For each cell in the report component, the first class whose condition is satisfied by the cell's row is assigned to the cell.
-
If there are no conditional declarations, or if none of the conditions is satisfied, the class in the first unconditional declaration is assigned to the report component. All subsequent declarations for that component are ignored.
subtype
Is an optional attribute and value needed to specify certain kinds of report components completely. For example, COLUMN and a column identifier are needed to specify a particular report column.
classname
Is the name of the Cascading Style Sheet class you are applying to format the report component. You can assign the same class to multiple report components.
Class names are case sensitive, and must agree with the case name in the class rule in the Cascading Style Sheet. (Note, however, that not all Web browsers enforce case sensitivity for class names.)
when
Is an optional WHEN attribute and value. Supply this to apply conditional formatting.
link
Is an optional URL or JAVASCRIPT attribute and value. Supply this if you want to link the report component to another resource.
Using an External CSS - A Graphical Overview
Three items are required to style a report with an external Cascading Style Sheet (CSS):
- An external Cascading Style Sheet that specifies formatting to be applied.
- A FOCUS StyleSheet in which you apply external CSS formatting attributes to your report components (this is not required if you format the entire report with the CSS).
- A link to the external Cascading Style Sheet from the report.
This example demonstrates the interaction.
Procedure: How to Format a Tabular Report With an External CSS
To format a report using an external Cascading Style Sheet (CSS):
- Specify the report formatting in the CSS. To specify formatting for:
- A report component, use a rule for any generic class (one not tied to an element). This Cascading Style Sheet rule declares the ColumnTitle generic class:
.ColumnTitle {font‑family:helvetica; font‑weight:bold; color:blue;}
- The entire report, use a rule for the BODY or TD elements (not for a class of these elements), and skip Step 2. This is an effective way to specify default report formatting, and generates more efficient report output than applying a CSS class to the entire report. This Cascading Style Sheet rule for the TD element specifies the element's font family:
TD {font‑family:helvetica}
Because this rule is for the TD element, the formatting is applied to an entire report, not just a report component.
- Assign classes to report components. In a FOCUS StyleSheet, use the CLASS attribute to assign a Cascading Style Sheet class to each report component that you wish to format. You can assign each component a different class, and you can assign the same class to multiple components. This FOCUS StyleSheet example formats ACROSS values by applying the formatting for the ColumnTitle class:
TYPE=AcrossValue, CLASS=ColumnTitle, $
- Link to the CSS. Link the external Cascading Style Sheet by assigning either the URL or the fully qualified pathname for the CSS file, through either the CSSURL FOCUS StyleSheet attribute or the CSSURL SET parameter, as shown below:
- TYPE=REPORT, CSSURL = c:\projects\reportstyles.css
- TYPE=REPORT, CSSURL=http://webserv1/css/reportstyles.css
You can accomplish the same thing using a SET command:
- SET CSSURL = c:\projects\reportstyles.css
- SET CSSURL=http://webserv1/css/reportstyles.css
Example: Formatting a Report Using a Cascading Style Sheet
This annotated report, which displays products currently offered by Gotham Grinds, is formatted using a Cascading Style Sheet (report01.css). The formatting specifies that:
- The default font family is Arial.
The style sheet formatting overrides the report heading default font family of Times New Roman. The heading is also in a larger point size and is center-justified.
- All column titles are in a bold font and have a light‑blue background.
- When a product's unit price is less than $27, the report displays that product row in green italics.
The report request and inline FOCUS StyleSheet follow:
TABLE FILE GGPRODS
HEADING
"</1 Current Products</1"
PRINT PRODUCT_DESCRIPTION UNIT_PRICE
BY PRODUCT_ID
ON TABLE SET PAGE‑NUM OFF
ON TABLE HOLD AS CSSEXAM2 FORMAT HTML
1. ON TABLE SET STYLE *
2. TYPE=REPORT, CSSURL=c:\Projects\report01.css, $
3. TYPE=HEADING, CLASS=headText, $
4. TYPE=TITLE, CLASS=reportTitles, $
5. TYPE=DATA, CLASS=lowCost, WHEN=N3 LT 27, $
6. ENDSTYLE
END
The external Cascading Style Sheet, report01.css, follows:
7. BODY {font‑family:Arial, sans‑serif}
8. TABLE {border:0}
8. TD {border:0}
9. .reportTitles {font‑weight:bolder; background:lightblue;}
10..lowCost {color:green; font‑style:italic;}
11..headText {font‑family:Times New Roman, serif; font‑size:larger;
text‑align:center}
- Begin the inline FOCUS StyleSheet.
- Link to the fully-qualified pathname (or URL, if Web-based) of the external Cascading Style Sheet report01.css.
- Format the report's heading using the Cascading Style Sheet's rule for the headText class.
- Format the report's column titles using the CSS's rule for the reportTitles class.
- For each report row for which the product's unit cost is less than $27, format that row using the CSS rule for the lowCost class.
- End the inline FOCUS StyleSheet.
- This CSS rule for the BODY element specifies the font family Arial, and if Arial is unavailable, the generic font family sans serif.
Because this is a rule for BODY, it is applied to the entire report: all text in the report defaults to Arial. You can override this for a particular report component by applying a rule for a generic class to that component, as is done in this procedure with the rule for the headText class (see line 11).
- These CSS rules for the TABLE and TD elements remove the report's default grid.
- This CSS rule for the generic class reportTitles specifies a bolder relative font weight and a light blue background color. The FOCUS StyleSheet applies this to the report's column titles (see line 4).
- This CSS rule for the generic class lowCost specifies the text color green and the font style italic. The FOCUS StyleSheet applies this rule conditionally to report rows for which the product's unit cost is less than $27 (see line 5).
- The CSS rule for the generic class headText specifies the font family Times New Roman, and if Times New Roman is unavailable, the generic font family serif. It also specifies a larger relative font size and center justification.
The FOCUS StyleSheet applies this rule to the report's heading. It overrides the default font family specified in the rule for the BODY element (see line 7).
The output is: