Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!DOCTYPE html> <title>My Example</title> <!-- ====================================================================== CSS - Place this in your <head> or in an external stylesheet. ====================================================================== --> <style> :root { /* Using an image from picsum.photos for demonstration. Replace with your own image. */ --fbh-bg-image: url('https://picsum.photos/id/1018/1600/1000'); --fbh-min-height: 80vh; --fbh-padding: 3rem 1.5rem; --fbh-text-color: #ffffff; --fbh-overlay-color: rgba(17, 24, 39, 0.5); --fbh-cta-bg: #fff; --fbh-cta-text-color: #111827; --fbh-cta-hover-bg: #f3f4f6; } .fixed-bg-hero { box-sizing: border-box; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; min-height: var(--fbh-min-height); padding: var(--fbh-padding); width: 100%; position: relative; display: flex; justify-content: center; align-items: center; text-align: center; /* The Parallax-Style Effect */ background-image: var(--fbh-bg-image); background-attachment: fixed; background-position: center; background-repeat: no-repeat; background-size: cover; } .fixed-bg-hero::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--fbh-overlay-color); z-index: 1; } .fixed-bg-hero * { box-sizing: border-box; } .fbh-content { position: relative; z-index: 2; max-width: 1000px; color: var(--fbh-text-color); } .fbh-content .title { font-size: clamp(2.5rem, 6vw, 4.5rem); font-weight: 800; line-height: 1.1; margin: 0 0 1rem; text-shadow: 0 2px 4px rgba(0,0,0,0.2); } .fbh-content .subtitle { font-size: clamp(1.1rem, 3vw, 1.25rem); margin: 0 0 2rem; max-width: 700px; margin-left: auto; margin-right: auto; } .fbh-content .cta { display: inline-block; background-color: var(--fbh-cta-bg); color: var(--fbh-cta-text-color); padding: 0.9rem 2.2rem; border-radius: 8px; border: none; font-size: 1.05rem; font-weight: 600; text-decoration: none; cursor: pointer; transition: background-color 0.3s ease; } .fbh-content .cta:hover { background-color: var(--fbh-cta-hover-bg); } /* Extra content section for demonstrating the scroll effect */ .scroll-demo-content-fb { padding: 4rem 1.5rem; background-color: #fff; color: #111827; } .scroll-demo-content-fb p { max-width: 700px; margin: 0 auto 1rem; line-height: 1.6; } </style> <!-- ====================================================================== HTML - Place this in your <body> where you want the component to appear. ====================================================================== --> <section class="fixed-bg-hero"> <div class="fbh-content"> <h1 class="title">Create a Lasting Impression</h1> <p class="subtitle">This simple and elegant effect adds a layer of depth, making your content more engaging and memorable.</p> <a href="#" role="button" class="cta">Get Started</a> </div> </section> <!-- This section is just for demonstration to create scroll space --> <section class="scroll-demo-content-fb"> <p>Scroll down to see the fixed background effect in action. Notice how the content in this section scrolls normally over the stationary background image of the hero above.</p> <p>The effect is created with a single line of CSS, `background-attachment: fixed;`, which "fixes" the background image to the viewport, while the rest of the page scrolls over it.</p> </section>