Search This Blog

Showing posts with label Display a page background image. Show all posts
Showing posts with label Display a page background image. Show all posts

Tuesday, July 1, 2025

How do I display a page background image

 

Adding a background image to an APEX page can enhance the user interface and make the application visually appealing. This can be done using CSS, Static Application Files, or inline styles.

Below are multiple approaches to accomplish this in Oracle APEX.

 

1. Using CSS to Set a Background Image

The most efficient way to apply a background image is by using CSS.

Steps to Add a Background Image via CSS

  1. Open Oracle APEX Page Designer.

  2. Select the Page Attributes section.

  3. Scroll down to the CSS section and find Inline CSS.

  4. Add the following CSS code:

body {

    background-image: url('&APP_IMAGES.background.jpg');

    background-size: cover;

    background-repeat: no-repeat;

    background-attachment: fixed;

    background-position: center;

}

  1. Click Save and Run the page to see the background image.

Explanation of CSS Properties:

  • background-image: Specifies the image to be used.

  • background-size: cover: Ensures the image covers the full page.

  • background-repeat: no-repeat: Prevents the image from repeating.

  • background-attachment: fixed: Keeps the background image static when scrolling.

  • background-position: center: Centers the image on the page.

 

2. Using a Static Application File for Background Image

If the image is stored in APEX under Static Application Files, reference it dynamically.

Steps to Upload and Use a Static File

  1. Navigate to Shared Components > Static Application Files.

  2. Click Upload File, select the image, and upload it.

  3. Copy the file reference URL from the uploaded file.

  4. Apply the CSS in Page Designer under Inline CSS:

body {

    background-image: url('#APP_FILES#background.jpg');

    background-size: cover;

    background-repeat: no-repeat;

}

APEX will dynamically replace #APP_FILES# with the correct image path.

 

3. Setting Background Image via Page Templates

If the same background image should be applied to all pages, update the Page Template.

Steps to Modify Page Template for Background Image

  1. Open Shared Components.

  2. Click on Themes and choose the theme in use (e.g., Universal Theme).

  3. Select Page Templates.

  4. Edit the Standard Page Template.

  5. Find the <body> tag inside the Template Definition.

  6. Add the following inline CSS before </body>:

<style>

    body {

        background-image: url('&APP_IMAGES.background.jpg');

        background-size: cover;

        background-repeat: no-repeat;

        background-attachment: fixed;

    }

</style>

  1. Save changes and apply them to all pages using the template.


4. Using JavaScript to Dynamically Change Background Image

If the background image should change dynamically based on user actions, use JavaScript.

Steps to Change Background Image Using JavaScript

  1. In Page Designer, navigate to Page Attributes.

  2. Under Execute when Page Loads, add the following JavaScript:

document.body.style.backgroundImage = "url('&APP_IMAGES.dynamic_background.jpg')";

document.body.style.backgroundSize = "cover";

document.body.style.backgroundRepeat = "no-repeat";

  1. This script changes the background when the page loads.

 

5. Changing Background Based on Page Conditions

To change the background based on specific page numbers or conditions:

  1. Go to Page Designer > Execute when Page Loads.

  2. Add the following JavaScript:

if ($v('P1_USER_ROLE') === 'Admin') {

    document.body.style.backgroundImage = "url('&APP_IMAGES.admin_background.jpg')";

} else {

    document.body.style.backgroundImage = "url('&APP_IMAGES.user_background.jpg')";

}

This changes the background dynamically based on user roles.

  

Displaying a background image in Oracle APEX can be done using CSS, Static Application Files, or JavaScript. The best approach depends on the application requirements. Using CSS is ideal for static backgrounds, while JavaScript is useful for dynamic changes based on conditions or user interactions.


EXAMPLE:

Step 1 – Click on the image from Shared Components > Static Application Files




Step 2  - Copy the reference value

A screenshot of a video

AI-generated content may be incorrect.

Your reference should look like this: 

#APP_FILES#JayGeeMarketplace/JayGeeMarketplaceReactive.JayGeeComplex.jpg


Step 3 – Go to the “Page” level of the page and change the inline CSS

A screenshot of a computer

AI-generated content may be incorrect. A screenshot of a computer program

AI-generated content may be incorrect.

Code: 

#t_PageBody {

background-image: url(#APP_FILES#JayGeeMarketplace/JayGeeMarketplaceReactive.JayGeeComplex.jpg);

background-size: 100% Auto;

}

Should look like this: