Table of Contents
More Resources
Adding a Background Color

Add a background color to your header or footer.

You want to add a background color to your header or footer.

Note: We’ll use the “insertBodyOddHeader” template as an example, but this can be used for any of the header or footer templates, just be sure to change the template name and the flow-name.
    Modifying the static-content.xsl file
  1. In order to add a background color, you”ll need to add two more fo groups into the header definitions located in the static-content.xsl file. Add the bolded lines below into your XSL file so that your main block is within a block-container.

    Expected Result
    < xsl:template name="insertBodyOddHeader"> 
      < fo:static-content flow-name="odd-body-header"> 
        < fo:block-container xsl:use-attribute-sets="__headerBackground"> 
          < fo:block xsl:use-attribute-sets="__body__odd__header"> 
            {{Content of Header}}
          < /fo:block> 
        < /fo:block-container> 
      < /fo:static-content> 
    < /xsl:template> 

  2. Modifying the custom-attrs.xsl file
  3. Now, you need to adjust the attribute sets that are located in your custom-attrs.xsl file. First, add a __headerBackground attribute set with the following contents:

    Expected Result
    < xsl:attribute-set name="__headerBackground"> 
      < xsl:attribute name="background-color"> #FF0000< /xsl:attribute> 
      < xsl:attribute name="position"> absolute< /xsl:attribute> 
      < xsl:attribute name="left"> 0< /xsl:attribute> 
      < xsl:attribute name="width"> 
        < xsl:value-of select="$page-width"/> 
      < /xsl:attribute> 
    < /xsl:attribute-set> 
    The bolded line above is the background-color attribute. Set the value of this node to the hexadecimal value of the color you want your header to be. In the example above, it is set to red.

  4. Next, you have to adjust the attribute set used on the fo:block element in Step 2. In this example, it is “__body__odd__header” but yours might be different. Add the following lines into the attribute set:

    Step Information
    < xsl:attribute name="padding-top"> 0.15in< /xsl:attribute> 
    < xsl:attribute name="padding-bottom"> 0.15in< /xsl:attribute> 
    < xsl:attribute name="margin-left"> 
      < xsl:value-of select="$page-margins"/> 
    < /xsl:attribute> 
    < xsl:attribute name="margin-right"> 
      < xsl:value-of select="$page-margins"/> 
    < /xsl:attribute> 
    Note:You can adjust the vertical location of your header content by adjusting the padding values.
  5. [Optional] You may also need to change the color of the header text if you’re using a dark background color. The code below will set the text color to white:

    Step Information
    < xsl:attribute name="color"> #fff< /xsl:attribute> 

You added a background color to your header or footer. An example of the output: