Background image that covers the entire screen, div elements that scroll on top of the landing screen initially

As a beginner in the world of coding, I apologize for any simple errors in my attempt. Despite researching this issue, I have not been able to find a precise solution that fits my needs.

My goal is to create a full-screen background for the landing page. The landing page should feature a div with title/intro content centered vertically and horizontally. When scrolling down, I want a white div to cover the entire screen width, overlaying the background and causing the title div to move upwards accordingly.

This is the code snippet I have crafted so far:

html,body{
    height: 100%;
}

body{
    font-family: 'American Typewriter', serif;
    font-weight: lighter;
    background: url('https://upload.wikimedia.org/wikipedia/commons/8/83/An_old_barn_with_the_Big_Horn_Mountains_in_the_background._Not_far_from_Sheridan,_Wyoming.JPG') no-repeat 50% 50%;
    background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    -webkit-background-size: cover;
}

div.name{
    font-size: 100px;
    color: #fff;
    display: block;
    margin: 0 auto;
}

div.container-intro{
    height: 100%;
    width: 100%;
    display: table;
    margin: auto;
}

div.container-inner{
    text-align: center;
    vertical-align: middle;
    display: table-cell;
}

a.main-link{
    border: 3px solid #fff;
    padding: 5px;
    color: #fff;
    font-size: 20px;
    text-decoration: none;
    width: fixed;
}

div.big-white{
    background-color: #fff;
    width: 100%;
    margin: auto;
}

The "big-white" div is intended to span 100% width and scroll over the background, shifting the initial divs upward. I hope this explanation clarifies the concept better.

Answer №1

If I understand correctly what you are asking for, simply include fixed in your CSS background property and set the body margin to 0px.

body{
    margin:0px;
    font-family: 'American Typewriter', serif;
    font-weight: lighter;
    background: url('https://example.com/image.JPG') no-repeat 50% 50% fixed;
    background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    -webkit-background-size: cover;
}

Answer №2

Include the background-repeat attribute in the CSS for your body element.

body{
    ...
    background-repeat: no-repeat;
}

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

Determine the cost for every individual line

I need help figuring out how to calculate the price for each row. Whenever I choose a quantity, it's showing the same price for both rows. Check out my demo here: https://jsfiddle.net/keyro/fw8t3ehs/2/ Thank you in advance! HTML: <table class=" ...

Is there a way to automatically increase the input id when adding a new row?

I have been working on dynamically adding new inputs and trying to assign a new ID that increments by 1 each time I add a new input. However, I am facing an issue where the value is not incrementing as expected. Can someone please help me identify what&apo ...

Overlay a div on top of an image in an HTML email

To display text over an image in HTML email, I am looking for a solution since using margin or position is not working as required. Below is the code snippet I have tried: <div style="padding-right:25px;padding-left:20px"> <div style="padding-t ...

Changing the counter using dual buttons in Vue.js

I am facing an issue with updating the counter when using both the add and remove buttons. The add button functions correctly, but unfortunately, the delete button does not update the counter as expected. Below is a picture showcasing the problem at hand: ...

Guide to swapping images using HTML forms and JavaScript

I have been attempting to create an image swapping code using a form with two drop-down options. The options are for color choices for an item, in this case, let's call it a widget, with both exterior and interior colors. I have been brainstorming on ...

Unable to showcase Mysql search outcomes in a distinct div section

I have been working on a project to showcase MySQL results by utilizing three different sections/divisions. In Division 1, there are radio buttons that allow for selecting and viewing the results based on different criteria. Division 2 contains text indica ...

Tips for implementing a toggle feature for an ion-card element

I am looking to create a toggle effect on ion-card, where clicking on the card will highlight it until either unclicked or another card is clicked. Similar to this - https://i.sstatic.net/MH5WA.png How can I achieve this effect on ion-card? Here is my H ...

Prevent users from viewing or editing profiles of other users

I need to enhance the security of my application by restricting users from accessing profiles of other users. route.js router.get('/currentUser/:username', userAuth, (req, res) => { User.findOne({ username: req.params.username }).the ...

JavaScript Recursive Function for Generating FancyTree JSON Structure

I'm currently building an array of JSON objects for FancyTree (https://github.com/mar10/fancytree/wiki/TutorialLoadData). My JSON source is from the Jira REST service, and its structure can vary widely. Therefore, the code to construct the array of JS ...

Troubleshooting Problem with Retrieving Files Using jQuery Ajax

I am attempting to use ajax to retrieve the contents of a file, but it doesn't seem to be functioning properly. I'm not sure why this is happening, as I have copied the same code from the examples on w3schools.com. $().ready(function(){ ...

Nested div within another div, shifting position relative to scrolling (React)

My goal is to create a unique effect where an object falls from the sky as the user scrolls down the page. The concept involves having the object div remain stationary in the center of its parent container, positioned 50 pixels from the top. However, when ...

Executing script once the DOM has completed loading

In my project, I'm dynamically generating menu items for a menu bar based on headers from external files that are imported using an XMLHttpRequest(). The menu bar is then updated as I navigate through different pages. Everything works smoothly. Each ...

Mastering HTML Tag Styling within Visual Studio

I'm looking for assistance on how to automatically format HTML tags using the Ctrl + K, Ctrl + D shortcut. For example: <label id="myLabelId">Hello</label> should be reformatted to: <label id="myLabelId"> Hello </label> ...

The nodejs express application encountered a CSRF token mismatch when attempting to make an ajax post request

Software Stack: Node.js, MongoDB, Handlebars, Bootstrap In controllers/products/index.js module.exports = function (router) { router.post('/add',function(req,res){ // implementation logic }); }; On the website, users can add pr ...

The Vue component mistakenly saves the image to the incorrect location when the file @change event is triggered

I've encountered an issue with my image slider component. Users have the option to add an extra image to the end of the slider, but when there are multiple instances of the same slider component on a page, it always adds the image to the first compone ...

What are some ways to implement dangerouslySetInnerHTML in conjunction with read-more-react from npm?

Is there a way to include dangerouslySetInnerHTML in a text field without receiving an error? <ReadMoreReact text={yourTextHere} min={minimumLength} ideal={idealLength} max={maxLength} readMoreText={read ...

Create automated scripts with Selenium using the programming language JavaScript

Is it possible to create selenium webdriver scripts using only javascript? If so, what are the benefits of choosing javascript over languages like java or C#? In what situations would javascript be the preferred option? Appreciate your insights. ...

Transforming JSON keys in Angular

As a newcomer to angular and API integration, I am facing an issue with ngCharts in my project. The chart specifically requires the keys names in JSON to be "value" and "name", but the API I am using provides keys named "count" and "label". Is there a way ...

An issue has arisen where I encounter the error message: 'TypeError: callback is not a function', even though the function appears to be continuing to run successfully

Encountering an error message 'TypeError: callback is not a function' while attempting to execute a particular function. Here is the code snippet in question: const api = require('axios'); getData(printData); async function getData ...

Modify the date format inside the content of an HTML element or its descendants (excluding their attributes)

I have been trying to reformat some dates using JavaScript. My initial approach was: var regex = /(\d{4})-(\d{2})-(\d{2})/g; $('.container td').each(function() { $(this).html($(this).html().replace(regex, '$3-$2-$1')); ...