Unable to view the HTML division

I am struggling with my website creation as I encounter issues with the .Main div. Despite setting background-color: orange; in the CSS, the color is not visible on the page. The inspector shows that it is positioned at 1440 x 0. Any assistance would be greatly appreciated.

Here is the code snippet I have so far...

const cursor = document.querySelector('.cursor')
const main = document.querySelector('.Main');

let cursorSize = 50;

document.addEventListener('mousemove', (event) => {
  
    cursor.style.left = `${event.clientX - cursorSize / 2}px`;
    cursor.style.top = `${event.clientY - cursorSize / 2}px`;

    const isSelectable = event.target.tagName === 'P' || event.target.tagName === 'H2';
    if (isSelectable) {
        cursor.classList.add('hide'); // Hide the cursor when mouse is over text or text is selected
        main.classList.add('cursor-text');
    } else {
        cursor.classList.remove('hide'); // Show the cursor when mouse is not over text and no text is selected
        main.classList.remove('cursor-text');
    }
});

document.addEventListener('mousedown', (event) => {
    cursorSize = 20;
    pointerStyle(event, cursorSize)
});
  
document.addEventListener('mouseup', (event) => {
    cursorSize = 50;
    pointerStyle(event, cursorSize)
});

let pointerStyle = (event, size) => {
    let newX = event.clientX - size / 2;
    let newY = event.clientY - size / 2;
    
    cursor.style.width = `${size}px`;
    cursor.style.height = `${size}px`;
    cursor.style.left = `${newX}px`;
    cursor.style.top = `${newY}px`;
}
body {
    font-family: 'Montserrat', sans-serif;
    overflow-x: hidden;
    width: 100%;
}

.Main{
    cursor: none;
    background-color: orange;
}

.cursor{ 
    position: absolute;  
    width: 50px;
    height: 50px;
    top: 0;
    left: 0; 
    background-color: #84E6BC;
    border-radius: 50%;
    pointer-events: none;
} 

.cursor.hide {
    opacity: 0;
    pointer-events: none;
}

.cursor-text {
    cursor: text;
}

.banner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    height: 40%;
    background-color: #FFFFFF;
    border-radius: 60px;
    box-shadow: 0px 6px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
  
.title {
    font-size: 2em;
    font-weight: bold;
    text-align: center;
    margin-bottom: 40px;
}
  
.subheading {
    font-size: var(--p-size);
    text-align: center;
    margin-bottom: 40px;
}
  
.smiley {
    fill: #84E6BC;
}
<div class="Main">
    <div class="banner">
        <h2 class="title">Thank you!</h2>
        <p class="subheading">I really appreciate you contacting me. I will be in touch shortly.</p>
        <svg class="smiley" xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" viewBox="0 0 16 16">
            <path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zM7 6.5C7 7.328 6.552 8 6 8s-1-.672-1-1.5S5.448 5 6 5s1 .672 1 1.5zM4.285 9.567a.5.5 0 0 1 .683.183A3.498 3.498 0 0 0 8 11.5a3.498 3.498 0 0 0 3.032-1.75.5.5 0 1 1 .866.5A4.498 4.498 0 0 1 8 12.5a4.498 4.498 0 0 1-3.898-2.25.5.5 0 0 1 .183-.683zM10 8c-.552 0-1-.672-1-1.5S9.448 5 10 5s1 .672 1 1.5S10.552 8 10 8z"/>
        </svg>
    </div>
    <div class="cursor"></div>
</div>

Answer №1

The content located within the main section is styled with position: fixed, causing it to remain in a specific position on the screen regardless of scrolling. This CSS property removes the element from the normal flow, leading to its collapse to a height of 0px since there is no content occupying space inside.

Take a look at the code snippet below. I have disabled the positioning code and utilized margin: 0 auto instead to centrally align the .Banner element horizontally.

Just a side note unrelated to your question, you should switch the cursor's positioning from position: absolute to position: fixed to ensure that its location matches the actual cursor position when scrolling.

const cursor = document.querySelector('.cursor')
const main = document.querySelector('.Main');

let cursorSize = 50;

document.addEventListener('mousemove', (event) => {
  
    cursor.style.left = `${event.clientX - cursorSize / 2}px`;
    cursor.style.top = `${event.clientY - cursorSize / 2}px`;

    const isSelectable = event.target.tagName === 'P' || event.target.tagName === 'H2';
    if (isSelectable) {
        cursor.classList.add('hide'); // Hide the cursor when mouse is over text or text is selected
        main.classList.add('cursor-text');
    } else {
        cursor.classList.remove('hide'); // Show the cursor when mouse is not over text and no text is selected
        main.classList.remove('cursor-text');
    }
});

document.addEventListener('mousedown', (event) => {
    cursorSize = 20;
    pointerStyle(event, cursorSize)
});
  
document.addEventListener('mouseup', (event) => {
    cursorSize = 50;
    pointerStyle(event, cursorSize)
});

let pointerStyle = (event, size) => {
    let newX = event.clientX - size / 2;
    let newY = event.clientY - size / 2;
    
    cursor.style.width = `${size}px`;
    cursor.style.height = `${size}px`;
    cursor.style.left = `${newX}px`;
    cursor.style.top = `${newY}px`;
}
body {
    font-family: 'Montserrat', sans-serif;
    overflow-x: hidden;
    width: 100%;
}

.Main{
    cursor: none;
    background-color: orange;
}

.cursor{ 
    position: absolute;  
    width: 50px;
    height: 50px;
    top: 0;
    left: 0; 
    background-color: #84E6BC;
    border-radius: 50%;
    pointer-events: none;
} 

.cursor.hide {
    opacity: 0;
    pointer-events: none;
}

.cursor-text {
    cursor: text;
}

.banner {
    /*position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);*/
    margin: 0 auto; /* <-- Added this to horizintally center this element*/
    width: 60%;
    height: 40%;
    background-color: #FFFFFF;
    border-radius: 60px;
    box-shadow: 0px 6px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
  
.title {
    font-size: 2em;
    font-weight: bold;
    text-align: center;
    margin-bottom: 40px;
}
  
.subheading {
    font-size: var(--p-size);
    text-align: center;
    margin-bottom: 40px;
}
  
.smiley {
    fill: #84E6BC;
}
<div class="Main">
    <div class="banner">
        <h2 class="title">Thank you!</h2>
        <p class="subheading">I really appreciate you contacting me. I will be in touch shortly.</p>
        <svg class="smiley" xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" viewBox="0 0 16 16">
            <path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zM7 6.5C7 7.328 6.552 8 6 8s-1-.672-1-1.5S5.448 5 6 5s1 .672 1 1.5zM4.285 9.567a.5.5 0 0 1 .683.183A3.498 3.498 0 0 0 8 11.5a3.498 3.498 0 0 0 3.032-1.75.5.5 0 1 1 .866.5A4.498 4.498 0 0 1 8 12.5a4.498 4.498 0 0 1-3.898-2.25.5.5 0 0 1 .183-.683zM10 8c-.552 0-1-.672-1-1.5S9.448 5 10 5s1 .672 1 1.5S10.552 8 10 8z"/>
        </svg>
    </div>
    <div class="cursor"></div>
</div>

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

Broaden the default className attribute of the component

Greetings! I'm currently using Bootstrap with React and I am trying to figure out how to extend my component by passing className props deeper. Within my atom component, I have two separate files. The first one contains the component declaration. B ...

Using sql.js to import CSV files into SQLite databases

Is it possible to import a CSV file into a SQLite database using JavaScript instead of the command line? I am currently utilizing the sql.js library to work with SQLite in Javascript. I appreciate any help or suggestions on how to accomplish this task. Th ...

Is it possible to utilize the userId instead of the jwt token in this scenario?

Is it a good practice to hash the userId and store it in local storage, then send unhashed user id in authorization header on every route for server-side validation? Will this approach ensure security? ...

Is there a way to trigger a function upon the loading of a template in Angular 2?

I'm a newcomer to angular2 and I need to trigger a function when a template loads or initializes. I have experience with achieving this in angular1.x, but I'm struggling to figure out how to do it in angular-2. Here's how I approached it in ...

Animations with absolute positioning not rendering correctly in Safari

I recently created a basic animation that involves setting an element to "position: absolute" in order to translate it. Everything functions perfectly as intended on Chrome, however, when testing it on Safari, the absolute positioning seems to be completel ...

Encountering difficulties hosting create-react-app build on shared server, receiving 404 errors specifically linked to the chunk.js file

After working smoothly with create-react-app, I encountered an issue when attempting to create a build. Following the command: npm run build The build was successfully created. However, upon downloading and uploading the build file to a shared server via ...

Trouble with top attribute functionality within animate function

Why does the top attribute in the animate function of JQuery not seem to work, while the opacity attribute functions correctly in the code snippet below? $(function() { $(window).on('scroll', function() { ...

Exploring the potential of Django to efficiently implement multiple listviews on a single webpage

Recently started working with Python and Django, but I may have bitten off more than I can chew. If anyone has the time to help educate me, I would greatly appreciate it. My main model deals with "work orders," each of which is linked to subsets of data. I ...

Refresh the data in a table upon clicking the menu

I am looking to develop an accordion MENU, but unsure if I should use divs or <ul>. When a submenu is clicked, I want to execute a mysql query to update the data in the table next to the menu. I'm not sure of the best approach and whether to uti ...

Transferring data between Jade templates

In the process of building a compact CMS system prior to diving into Node.js websites using Express, Jade, and Bootstrap, I encountered a minor setback. To enhance modularity, I am employing includes for various components like the navigation header on th ...

JavaScript node_modules import issue

I've been grappling with this issue for quite some time now. The problem lies in the malfunctioning of imports, and I cannot seem to pinpoint the exact reason behind it. Let me provide you with a few instances: In my index.html file, which is complet ...

Creating a Form in a Popup with Bootstrap

I have implemented Bootstrap on my website. Check it out at: hubb.tekkkz.com I am facing an issue where, when clicking on the login/register button on the right, the modal pops up. However, the user input elements within the modal are not taking up the ful ...

Utilizing References in React Components

One of the challenges I am facing involves a Container that needs references to some of its child components: const Container = () => { const blocks: HTMLDivElement[] = []; return ( <div> <Navigation currentBlock={currentBlock} ...

Angular JS Retrieving Data in the Background with the Assistance of $timeout or $interval Service

Looking to fetch data from a webapi in the background using either the $timeout or $interval service in Angular JS. I have some concerns about how the $timeout and $interval services work. I've run into issues when incorporating these services into m ...

In all tests, except for the initial one, the DOM is not updated by test-utils once triggers have been fired

I have been facing an issue with checking for error messages related to field completion in HTML/DOM after vuelidate is triggered. The functionality works properly after the click trigger, and all tests pass successfully - including mounting, element searc ...

Visit the embedded AJAX feature that is failing to show any results

I've been working on this seemingly simple problem for days now, but I'm still stuck. I have the following Go code... package main import ( "fmt" "net/http" "html/template" "database/sql" _"github.com/mattn/go-sqlite3" ...

Mouseover function ceases to function once an element is dropped

After referencing this discussion, I successfully managed to drag items from one scroll overflow to another. However, the issue arises when these items (or their clones) are in the other scroll overflow as they do not respond to .mouseover(). The goal is ...

"Efficiently transferring a large file using AJAX and sending it via POST to a

I am facing a challenge with a small script that I am developing. The script is designed to download relatively large files (around 15Mb each) from one domain using AJAX, and then upload/post them to another domain also through AJAX. Downloading the files ...

Enhance the color scheme of your collapsed or expanded Bootstrap NAV for mobile devices

Currently working on customizing the navbar using Bootstrap. I've been able to style it perfectly for both desktop and mobile devices in its initial state. The issue arises when attempting to style the navbar in its expanded and collapsed states on m ...

Guide on moving elements to a different list with the help of the Angular DragDrop CDK Service

I encountered a unique situation while working on my project where I needed to implement a drag and drop feature for multiple lists using Angular CDK's DragDrop service. While I was able to successfully move items within a single list, transferring an ...