Elements positioned absolutely using the ::after and ::before pseudo-elements do not adhere to the very bottom of the body

Feeling a bit crazy right now! Haha. I'm facing a challenge in positioning an image at the bottom of a webpage. It seems to work fine when the page width is larger, around 1360px, but as soon as I shrink it to 1206px or less, the image gets pushed up, leaving space at the bottom like shown in the image below (The green box represents the image). https://i.sstatic.net/CmSIP.png

The CSS code used to position the green image is:

    body::after {
    content: "";
    width: 556px;
    height: 767px;
    position: absolute;
    bottom: 0;
    right: 10%;
    display: block;
    background-image: url("imagens/ghost-dog.png");
    background-size: contain;
    background-repeat: no-repeat;
    z-index: -1;
}

In addition, there is a purplish shadow added for transparency that has also not stuck to the bottom. This was achieved using this CSS:

    body::before {
    background-color: rgba(0, 0, 0, 0.1);
    position: absolute;
    display: block;
    content: "";
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

To add to the confusion, the background of the body fits all screen sizes as expected with the following CSS:

body {
    color: #fff;
    font-size: 15px;
    line-height: 21px;
    font-family: "comfortaa-regular";
    background-color: var(--cor-roxa);
    background-image: url("imagens/logo-bg.svg");
    background-repeat: repeat;
}

html, body {
    height: 100%;
}

I've attempted setting the position of the body to relative, but unfortunately, it did not resolve the issue. Just in case, I am using Bootstrap and my div layout resembles the image provided here:

https://i.sstatic.net/mYYNn.png

Any helpful suggestions would be greatly appreciated!

Answer №1

It can be challenging to identify the cause without an example to examine, but one possibility that comes to mind is a child element with a margin exceeding its parent container's boundaries, causing it to extend past the window boundary.

I suggest verifying your elements and adjusting any margins to see if it resolves the issue.

If you share your code on a fiddle, I'd be happy to review it and update my response if necessary.

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

Updating Icons in HTML Using Local Storage and Implementing a Dark Mode Feature Using JavaScript

My latest project involved creating a dark mode button along with a custom dark theme. The theme is stored in Local Storage to ensure consistency. However, I have encountered an issue where, upon page reload, the site remains in dark mode but the button ic ...

Basic AJAX request not functioning properly

I am encountering an issue with a very simple AJAX call on my localhost. I am using a Windows 10 Machine with XAMPP running. I have checked the packages, and it seems that the AJAX request is not being sent to handle.php. Can someone help me figure out wha ...

Parallax Effect malfunctioning on iPhones

Hey there, I recently created a parallax UI using pure CSS. It seems to work fine on Android and desktop browsers, but when I tested it on iOS or iPhone, the parallax effect doesn't seem to be working correctly. I'm not sure why this is happening ...

retrieve the parent id of <ul> elements and store them in an array

Here is the html code I am working with : <form> <ol> <li id="1" name="grandparent">Grand Parent <ol> <li id="2" name="parent">Parent <ol> <li id="3" name="child">Child < ...

Creating an HTML form that submits data to a PHP script, which then saves the

Looking for some assistance with a PHP issue I am having. I know my way around PHP, but I wouldn't say I'm an expert. Here's the problem: I have created an HTML form (form.html) and now I want the output from formular.php to be saved as a u ...

The navigation menu links that are meant to stay fixed at the top of the page are not functioning

On my website, I implemented Foundation's Magellan sticky menu at the bottom. Strangely, when I view the site in Firefox, the menu functions properly. However, when I try to open it in Google Chrome, the links don't work (and the cursor pointer d ...

CSS for the root folder of an ASP.NET website

After deciding to venture into ASP.NET, I quickly encountered my first obstacle. The folder structure is as follows: \ ->Admin -->Admin.Aspx ->CSS -->Style.css ->Images -->bg.gif Default.aspx Default.master Both admin.aspx and ...

Having trouble getting the same styles to show up on .class::before and .class::after elements, even though I've applied them. The changes aren't reflecting on the live server

Currently, I am working on a project that involves an ordered list (ol), and I am trying to add pseudo elements (::before,::after) to enhance its appearance. Strangely, when I write ::before and ::after separately, the styles are applied and visible on the ...

I am struggling with aligning the list items side by side

I am currently facing an issue with my list items that have anchor tags. They are currently set to display block with background images, but I want them to display inline. However, they are stacking on top of each other instead. The ul is being generated b ...

Delete the designated column from the table

I am having difficulty with hiding and showing table columns using checkboxes. I need to eliminate the Mars column (in bold) along with its corresponding data (also in bold). Once the Mars column is removed, I want the Venus column and its data values to ...

Encountered a Three.js error labeled as Uncaught TypeError while trying to follow

I've been following a tutorial on how to integrate three.js into my project from this video: https://www.youtube.com/watch?v=1TeMXIWRrqE I copied the source code provided at the bottom of this webpage: After downloading and extracting the model into ...

Styling in sass gets even more powerful when using custom selectors that are

Using these mixins makes it easy to work with BEM syntax in sass 3.3.2: =b($name) .#{$name} @content =e($name) &__#{$name} @content =m($name) &--#{$name} @content +b(menu) +e(item) color: grey +e(item) +m(alert) ...

Is it possible to slide-toggle and alter the background color of a div when clicked?

Imagine having several div's on a webpage all with the ID of "Toggle". Each div contains two other smaller divs. "Headline" which is always visible. "Comment" which appears/disappears when the headline is clicked (initially hidden). How could I ac ...

"Share your social media profiles without redirecting users to new tabs

Currently in the process of launching my own website using the free Portra theme. So far, everything has been going smoothly with this widget free template. However, I have encountered an issue with my social links opening in the same window. I would prefe ...

What is the best approach to dynamically bind a style property in Vue.js 3?

I am currently working with vue3 and I am trying to apply dynamic styles. This is how my vue3 template looks: <ul> <li v-for="(question, q_index) in questions" :key="q_index" v-show="question.visible" :style="{ ...

Is it possible to swap the src of the Next.Js Image Component dynamically and incorporate animations in the

Is there a way to change the src of an image in Nextjs by using state and add animations like fadein and fadeout? I currently have it set up to change the image source when hovering over it. const [logoSrc, setLogoSrc] = useState("/logo.png"); <Image ...

Using jQuery, generate a div element and display it in full screen mode

Is it possible to dynamically create a full-screen div using jQuery directly from JavaScript without the need to first define it in the HTML and then make it visible with jQuery or CSS? UPDATE After some troubleshooting, I found a solution to my issue: ...

Using Javascript to Swap the Content of an Element

Recently, I've been delving into the world of javascript and have hit a roadblock. I understand how to instruct javascript to set a specific value for an ID, but now I have a new challenge: I want to create javascript code that can retrieve informati ...

When is the ideal moment to utilize SASS extensions?

My current team uses SASS and I've noticed that we're extending very simple styles in our code. I fail to see the purpose of doing this. Am I overlooking something? Below are some examples of styles from a _Common.scss file that is imported and ...

What is the best way to position an image at the center in Bootstrap?

I'm attempting to horizontally center an image within the Bootstrap 4 Alpha 6 carousel. Despite my efforts, including utilizing center-block, I have been unable to achieve the desired result. Here's a link to what I've attempted so far: ht ...