Background filling the entire screen with a fixed position behind the elements on the page and in front of

Here are the two sample images I am using to give you an idea.


This represents the background of the body:


This is the background for the fixed position div:

Above these two elements lies the website content. In between them, there are some moving stars created using pure CSS without any user interaction involved.

However, a problem arises when the user scrolls. The fixed background tends to break into parts, gets stuck in its positioning, and at times, the body background image disappears, revealing only the background color while scrolling.

body {
   font-family: 'LatoRegular', 'Lucida Grande', Helvetica, sans-serif !important;
   line-height: 21px;
   color: #636e7b;
   overflow: hidden; /*removes it after preloader quits*/
   position: relative;
   background: #1d2939 url("../images/backgroundv2.jpg") fixed;
   background-repeat: no-repeat;
   background-size: 100% auto;
   background-position: center top;
}

#fix {
    background: transparent url("../images/backgroundv2.png") fixed;
    background-repeat: no-repeat;
    background-size: 100% auto;
    background-position: center top;
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
    -webkit-transform: translateZ(0);
}

I would appreciate any ideas or suggestions to resolve this issue.

(To view the buggy version while scrolling, click here)

Answer №1

After experimenting with your code, I found that it functions as intended. However, I may have approached it differently as the code appears a bit messy. Nonetheless, it achieves your desired outcome. Here is a fiddle for reference: http://jsfiddle.net/domusnetwork/Lkrkp/

If I misunderstood anything, please let me know.

In regards to your issue, it seems to stem from the elements layered on top of your background. You could try using the following code snippet as a possible solution:

html { 
  background: url(images/bg.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

If this does not resolve the problem, you may want to consider implementing one of the techniques outlined in this article: http://css-tricks.com/perfect-full-page-background-image/

Have a wonderful day :)

Answer №2

Just wanted to express my gratitude for the assistance. Luckily, I managed to identify the issue. It turns out that the moving stars were causing the problem. They were created by the codepen author using a simple CSS technique with an excessive amount of box-shadows as dots in 3 different div sizes. Because there were so many stars, it was causing a significant strain on the page rendering during scrolling. Removing one size of the stars resolved the issue, and now the scrolling is smooth, the background remains visible, and everything is working perfectly.

It's clear that prioritizing performance is crucial.

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

Having trouble with ng-click not correctly updating values within ng-repeat

Here is the code snippet: <div ng-repeat="data in products"> <div class=edit ng-click="dataUI.showEdit = true; content = data;"> </div> <div ng-repeat="renew in data.renewed"> <div class=edit ng-click="dataUI ...

The title attribute fails to display the entirety of the content

My div has a title attribute with 4000 characters, but when I hover over it, the full content is not displayed. Is there a way to show the complete text? https://codesandbox.io/s/strange-hugle-mvwu5 ...

Running a Node.js child process upon clicking an HTML button

I need to create a basic webpage where clicking a button will open the command prompt. This is my goal. Below are the HTML and Node.js code snippets. test.html <html> <head> </head> <body> <p>guru</p> <form a ...

Implementing a PHP script to prompt the user to input two random integers and sum them up on a webpage through $_POST method

My current project involves creating an interactive adding game using PHP and HTML. In this game, the user is required to guess the correct sum of two randomly generated integers. However, I am encountering an issue where each time the user submits their a ...

Guide on obtaining the file path of an uploaded file through the use of HTML, JavaScript, and PHP

After successfully uploading an image from my drive, I am encountering an issue where I am unable to locate the folder path of that image For example: C:\Images\Logo\Image.png $('#pngfile').change(function (e) { var tmppath = URL ...

Prevent a child DIV from adopting the style of its parent page

Imagine a scenario where you have a webpage with its own unique stylesheet. You decide to include a popup or modal at the end of the page using Javascript, but you want this popup to have its own distinct style. Since the content within the modal is dynami ...

Increasing the size of the td element when including a new row

Here is an html page example that I am working with: However, when I add a new row beneath the existing row that contains a div block and form within it, I notice that the td tag in the first row expands in width, as depicted in the image below. Below is ...

Conceal HTML Table Rows

I have a HTML table that showcases items and their respective daily information - usage, incoming shipments, and inventory. The goal is to initially hide the first two columns and reveal them on mouseover using jQuery. I am planning to assign a class to ea ...

Decoupling the Top Navigation Bar from the Side Navigation Bar

I currently have a top navigation bar with some menus and a side navigation bar with additional menus. I have applied styling to the vertical navigation bar, but it seems to be affecting all the navigation bars, resulting in an output as shown in the image ...

Category-Specific Page Display

Can anyone help with CSS coding using Wordpress Elementor to make a page only display posts from the coaching category? I attempted to use this selector article.type-post:not(.category-coaching) { display: none; }, but it doesn't seem to be functi ...

Calculate the total sum using the footerCallback function

I've written some code that retrieves data for the tbody of a table. Now, I want to add a tfoot to display the sum of the last column, and here's how I'm attempting to do it: var data = [ {Id: "1", Quantidade: "14", Preco: "3.10", }, ...

Incorporating HTML variables into a Django template without the need for escaping

I have encoded text in HTML format that looks like this: RT <a href="http://twitter.com/freuter">@freuter</a>... I would like to display this as formatted HTML, but I am unsure if there is a filter available to convert the encoded text back t ...

Guide to integrating the Duda White Label API with an HTML website

Currently, I am in the process of integrating the Duda White Label API into a .html page to ensure that it aligns with my custom CSS. To guide me through this task, I am referring to the instructions provided at: After inserting my API key, Password, and ...

Event Listener for Spelling Quiz Buttons: Check Correct and Incorrect Answers

I am currently in the process of developing a spelling quiz for a project website using HTML, CSS, and JavaScript. The idea is to present the user with a word that has two missing letters indicated by underscores. The user then selects the correct answer ...

To create space between the input field and button, utilize the input-group class for

Is there a way to insert a space between the input field and the button while using input-group in Bootstrap 3? Check out this jsFiddle for more information. <div class="container"> <div class="row"> <div class="col-md-12"> ...

Modify the anchor text when a malfunction occurs upon clicking

Whenever I click on the link, I am able to retrieve the correct id, but the status changes for all posts instead of just the selected item. Below is the HTML code: <div th:each="p : ${posts}"> <div id="para"> <a style="float: right;" href= ...

Exploring the Power of Nested *ngFor in Angular 2

I am struggling with passing indexes to a function where the first parameter (ii) is coming back as undefined. <div *ngFor="let tab of screen.data.tabs; let indexTab = i;"> <div *ngIf="tab.active"> <div *ngIf="tab.questions"&g ...

Is there a way to extract information from a <span> element with restricted access?

I'm currently utilizing bs4 and urllib2 to extract data from a website. Check out the webpage here. The goal is to retrieve the remaining digits of the telephone number 3610...... but beforehand, it's necessary to click on a button to reveal th ...

Dimming the background of my page as the Loader makes its grand entrance

Currently, I am in the process of developing a filtering system for my content. The setup involves displaying a loader in the center of the screen whenever a filter option is clicked, followed by sorting and displaying the results using JQuery. I have a v ...

Issue with custom checkbox not changing when bootstrap collapse occurs

I've been searching for a solution and experimenting with different methods, but I just can't seem to make it work. Below is a CodePen example that showcases a custom checkbox with a toggle function to show/hide a div when checked, along with a ...