How are these background images able to remain in a fixed position like this?

Trying to name this question correctly was a bit tricky. Hopefully I got it right.

I have a new client and they want their website to have a similar feel to .

If you check out the index page and scroll down, there's this cool 'smooth animation' where blocks slide up into the background image.

Here's what I mean: http://gyazo.com/8cafbab233930bd478723b48c5912263

So my question is, how do I achieve this effect? Is it just an image with text on top, or is it a background image? What rules do I need in place to make this happen?

Answer №1

You have the ability to achieve this using CSS as demonstrated below.

body{
  margin:0;
  padding:0;
}
.one{
  background-image:url('https://placekitten.com/g/1200/800');
  height:500px;
  background-size:cover;
  background-position:static;
   position: static;
    background-position: inherit;
    background-attachment: fixed;
  }
   
.two{
   height:500px;
  }
<div class="one"></div>
<div class="two">
  <p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vehicula sem mi, at faucibus ex consequat eu. Suspendisse bibendum nulla id nisl pulvinar, a lacinia nisi imperdiet. Nam eget mi congue, lacinia augue dictum, ullamcorper ex. Donec condimentum dolor nisl, eu tincidunt lacus congue et. Duis eu libero id nunc facilisis viverra a id velit. Suspendisse potenti. Fusce in nisi eu est consectetur fringilla vitae non nunc. Cras neque elit, pharetra at ipsum at, semper laoreet eros. Nunc eu dolor blandit, varius felis vel, congue turpis. Vestibulum ullamcorper leo odio, in mattis ante pretium nec. Ut sagittis luctus lacinia. Donec vehicula ullamcorper lectus, eget pretium nisi laoreet id. Cras id laoreet nunc, ac molestie lectus. Phasellus suscipit, risus eget fringilla posuere, urna eros venenatis ante, vel finibus lorem arcu a massa. Etiam at ante massa.
</p>
  <p>
Ut tempor fermentum dui sed placerat. In commodo velit at augue luctus bibendum. Aliquam ullamcorper tincidunt posuere. Sed congue sagittis est ac viverra. Cras eget lobortis leo. Donec rutrum elit purus, et sollicitudin lacus pulvinar eu. Maecenas sit amet metus nisi. Proin porta diam et rhoncus mollis. Quisque arcu leo, sagittis a iaculis gravida, pulvinar ac risus. Etiam lacinia urna nunc, eu tincidunt massa finibus id. Aliquam posuere, est at mollis rhoncus, libero neque varius dui, vel facilisis odio dolor non ante. Nullam tempor ligula non pellentesque aliquet. Donec rutrum est ac nisi tempus dapibus. Sed vel est eget nisi bibendum dapibus. In consectetur leo volutpat, pharetra dui in, consequat magna.
    </p>
...
</div>

Answer №2

To ensure your background image stays in position, you should utilize the 'background-attachment' property as shown below:

selector { 
    background-image: url(image.extension);
    background-attachment: fixed;
}

You have the flexibility to overlay any content on top of the background image. As you scroll, the background will stay fixed in its place while the content moves accordingly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Difficulty encountered in resetting progress bar post ajax form submission

Hello, I hope you can assist me with an issue I am facing regarding my progress bar. After submitting the form using AJAX to insert data, my progress bar does not reset. I would like it to reset after clicking the submit button. The progress bar is speci ...

Creating a web layout or template using HTML

Currently in the process of developing a website, my goal is to construct html templates that include placeholders for injecting pages/content, menus, and other elements. While I admire AngularJS for its flexibility in achieving this, I fear it may be too ...

Display a PDF file within an IFrame using JavaScript and then print it

Why is it so challenging to achieve? I've dedicated 48 hours to research this, yet it seems impossible! Although recent Chrome versions allow the parent window to access PDFs in iframes, both FF and IE prevent any interaction with the iframe that dis ...

Designing webpages by superimposing text onto images with customizable positioning

My current project involves developing an HTML document with a floor plan image as the main layer. On top of this image, I need to display employee names extracted from a database and positioned on the map based on a location variable within the database ...

When the browser is resized, the fadeIn() function restarts from the

My plan was to create a dynamic effect where a browser-sized div would rotate through 3 different backgrounds using jQuery's fading effect. However, I encountered an issue - whenever I resize the browser window, the effect restarts from the beginning ...

Terminate the ongoing PHP script execution

Is there a way to terminate the current PHP script? For instance: page.php <?php require('./other-page.php'); ?> <h4>this text is always displayed</h4> other-page.php <?php if($_GET['v'] == 'yes&ap ...

What is the process for connecting an HTML page to a CSS file located in a parent directory?

Here's the problem I'm facing: I recently encountered some organizational issues with my website, so I decided to reorganize my files for better classification. The current folder structure looks like this: www resources images ... css de ...

What is the best way to ensure a bottom tooltip stays perfectly aligned with the right edge of its corresponding element?

Currently, I am trying to implement a tooltip above my progress bar. However, the small tooltip that I have is not functioning correctly... This is how it currently appears: https://i.sstatic.net/ZJUyT.png I need the tooltip to display above the white d ...

Learn how to dynamically alter the background color of a webpage by utilizing a JSON API for random color selection

My goal is to trigger a javascript function onload that will dynamically change the background color of the webpage using random colors fetched from a JSON file. ...

Stop the webpage from scrolling when clicking on a ui-grid field

Is there a way to prevent page scrolling when clicking on a row field in ui-grid? I'm working with a page that has ui-grid, and each row includes an anchor tag with a URL value linked and target="_blank" to open in a new tab like the example below: ...

What could be causing this code to malfunction on a mobile device?

I am struggling to make this drag and drop function work on mobile devices. Despite implementing the code, it doesn't seem to function properly when accessed on my mobile phones. Here is the snippet of the code: copy = 1; $('.dragArea img&apo ...

Issues with Forms Affecting my Footer

One of the best methods to understand this issue is to view it live. The footer on the homepage looks great at www.fishingreports.com. However, there seems to be a problem with the footer at www.fishingreports.com/users/register. Whenever I copy the cod ...

Adjusting the height of an Angular CDK virtual scroll viewport based on dynamic needs

Currently, I am developing an Angular table with the cdk Virtual Scroll feature. Is there a method to adjust the scroll viewport's height dynamically? While the standard style property works, I am encountering difficulties setting the value using ngSt ...

Enhance your webpage with dynamic styling using third-party CSS animation

Apologies for any similarity to other questions on this topic. I have searched extensively, but any assistance would be greatly appreciated. I am utilizing a new animation library from Animista to animate specific elements on a test website. Animating ele ...

Replace the content within the iFrame completely

Is it possible to have a textarea where I can input HTML code and see a live preview of the webpage in an iframe as I type? For example, here is the code I'd like to write in the textarea: <!DOCTYPE html> <html> <head> ...

Opacity effect on input text when it exceeds the input boundaries

I'm having an issue: I need to create inputs with different states, including when the text is longer than the input itself. In this case, the extra text should fade out with a gradient transparency effect: Here is my current code snippet: .Input { ...

javascript for each and every textarea

I am looking to apply my JavaScript code to all the Textarea elements on my page. $_PAGE->addJSOnLoad(" $('.textarea').each(function() { $(this).keyup(function() { var characterCount = $(this).val().length; var mes ...

Strange HTML antics

On my website, I encountered an issue when trying to register without entering any information into the required fields. The errors were correctly displayed in this screenshot: However, after inserting random characters into each field and attempting to r ...

The inconsistency of Selenium's StaleElementReferenceException error and the variability of pageload completion codes is causing issues with clicking on elements

Big shoutout to the amazing stackoverflow community for always providing assistance. Lately, I've been grappling with the frustrating "StaleElementReferenceException" issue and haven't found a universal solution yet. Some helpful members have rec ...

Deciphering the Mysteries of HTTP Headers

I have been using various applications to evaluate the quality of my websites, and many of the improvements suggested relate to missing http headers. Some examples include Content-Security-Policy, Charset, etc... I decided to visit the Wikipedia page on ...