Hey! I would like to adapt the colour of my text in the Header to the background of the site like in this page: https://representclo.com
Has anyone a idea how to do this?
Thanks.
A user seeks to create a dynamic header text color that adapts to the site’s background color, similar to an example site they referenced.
Proposed Solution:
PageFly-Amelia provides a detailed technical implementation involving:
header.liquid or header.liquid.json in the Shopify theme codelight-bg or dark-bg to different page sections to indicate their background typeKey Technical Elements:
Status: Solution provided but not yet confirmed as implemented or tested by the original poster.
Hey! I would like to adapt the colour of my text in the Header to the background of the site like in this page: https://representclo.com
Has anyone a idea how to do this?
Thanks.
This is Amelia from PageFly - Landing Page Builder App
You can try with some steps below to make the dynamic color change on your header
header.liquid or header.liquid.json.
theme.css or styles.css in the Assets folder)./* Default header text color */
.site-header .dynamic-color {
color: #ffffff; /* Default white */
}
/* Change header text color to dark when on a light background */
.site-header.dark-text {
color: #000000; /* Black text for light backgrounds */
}
custom.js).Here’s an example of a basic JavaScript implementation:
document.addEventListener("DOMContentLoaded", function () {
// Get the header element
const header = document.querySelector(".site-header");
// Get all sections that affect the header color
const sections = document.querySelectorAll(".color-change-section");
window.addEventListener("scroll", () => {
sections.forEach((section) => {
const rect = section.getBoundingClientRect();
// Check if the section is in the viewport
if (rect.top <= 0 && rect.bottom >= 0) {
// Check if the section has a light background
if (section.classList.contains("light-bg")) {
header.classList.add("dark-text"); // Add class for dark text
} else {
header.classList.remove("dark-text"); // Default light text
}
}
});
});
});
light-bg) of the section.
Tips
light-bg or dark-bg, you can use data attributes (e.g., data-color="dark") to make your JavaScript logic more flexible.IntersectionObserver API to detect which section is currently in view and change the header text color accordingly..site-header .dynamic-color {
transition: color 0.3s ease-in-out;
}
Hope that my solution works for you.
Best regards,
Amelia | PageFly