Ensure that div2 remains aligned with the left, bottom, and right edges of the screen, while also maintaining a consistent distance of 400px below div

Currently, I am faced with a challenge involving two divs: one positioned at the top (div1) and the other at the bottom (div2).

The goal is to ensure that div2 maintains a consistent distance of 400px below div1 while also aligning its left, bottom, and right sides perfectly with the browser window. Regardless of screen size, these three sides should always be in sync. How can this be achieved?

So far, my attempts have involved the following CSS code:

.background-oval {
    background-color: #999;
    border-top-left-radius: 100%100px;
    border-top-right-radius: 100%100px;
    bottom: 0;
    height: 400px;
    position: absolute;
    width: 100%;
}

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

Answer №1

const box1 = document.getElementById("box1");
const box2 = document.getElementById("box2");

document.body.addEventListener("scroll", function(event) {
    box2.style.top = Math.max(
        - -(box2.style.top.slice(0, -2)) + box2.height + 400,
        document.body.scrollTop + innerHeight - box2.height
    ) + "px";
}

Note: - - is a method to convert a string into a number

Note2: This code assumes that box2 has position attribute and height

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

What is the best way to showcase my React App.js in an HTML document?

Is there a way to display my React app file (App.Js) within my Index.html file? <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="icon" href="%PUBLIC_URL%/fav ...

Dynamic jQuery for changing the CSS class is the way to go

Is there a way to dynamically change the css class of <li> elements in an ASP.NET masterpage? For example, if I click on the AboutUs.aspx link, I want to change <li class="single"> to <li class="active single"> when the page loads. Any s ...

When utilizing jQuery, HTML code may fail to render correctly

My JSP page contains the following HTML code. Interestingly, when <script type="text/javascript"> $("#department").autocomplete("department.jsp",{minChars: 4}); is placed after the first input type, the other fields do not show up in Internet ...

What causes the <td> element to extend beyond the boundaries of the <table>?

I need to add next and previous buttons to a <td> that has an asp:DropDownList. However, when I do this, the <td> ends up overflowing the width of the table. Here is the edited code snippet with the entire table included: <table class=" ...

Add a decorative frame around the heading and text block

I'm looking to encase both the header and paragraph in a single border. Right now, they each have their own separate borders. How can I combine them into one? <style type="text/css> h1, p { font-family: consolas; border: 2px solid #73AD21; bor ...

Video files embedded using Shopify's HTML code may not be visible on iPhones

Hello everyone, I hope you can help me with my issue! I have successfully integrated an HTML video onto my Shopify homepage, but I am experiencing some trouble when trying to view it on an iPhone. Instead of the video playing, I see a blank box. Below is ...

Swapping data between two HTML files and PHP

As I work on setting up a signup form for a MikroTik hotspot, I've encountered limitations with the device not supporting PHP. In order to pass the necessary variables from the device to an external PHP page where customer data will be saved and trial ...

Tips for placing an image in the bottom right corner of a frame

My goal on the Roman Numismatics page is to place the yellow 'bid' button at the lower right corner of each frame. Current code <p><a href="<?= $product->page_url() ?>"><img border="0" alt="Bid&qu ...

Tips for eliminating flutter for static menu with easyResponsiveTabs.js

Experiencing a flickering issue with the fixed menubar and easyResponsiveTabs.js in my project when scrolling down. Attempted to resolve it using jquery.noConflict(), but without success. Would appreciate any guidance on how to address this problem. ...

Issue with the height of content in Mobile Safari when using Bootstrap 4 columns

I have incorporated Bootstrap 4 into my website's design, specifically utilizing the bootstrap grid layout in flex mode. Within one of the columns, I have placed a button that I desire to fill the entire column width. I have achieved this by setting ...

The issue with IE-9 is that it is mistakenly picking up the placeholder value as

My HTML code looks like this: <input id="SLOCriteriaOtherText" name="SLOCriteriaOtherText" style="width: 100%;" type="text" data-role="autocomplete" placeholder="Enter name for 'other' metric..." class="k-input" autocomplete="off" role="textb ...

Utilizing AngularJS Directives: Extract a HTML attribute as a character sequence, employed as a key in a dictionary

My goal is to create an equation tag that utilizes a label attribute to determine which equation to display. Below is the code for my app: (function(){ var app = angular.module('mathDocument', []); app.directive('equation', fu ...

Issues with Firefox's flexbox functionality are preventing it from working

Hey there, I've created a bubble menu with a button using code. It functions perfectly on Chrome but seems to have some issues on Mozilla Firefox. You can check it out and give it a try. $(".roundedBallOuter").click(function(e) { $(this).toggleCl ...

Conceal an element if the angular attribute does not contain any value

Currently, I am facing an issue with an image element in my project. The path for this image is being fetched from an attribute present on my angular object. However, if this imagePath attribute is empty, a broken image is displayed. I want to avoid rend ...

Steps for generating a pop-up window for choosing a file from a local folder?

I'm looking to develop a popup window that displays all the files within a specific directory, for example, a /functions directory. The goal is to be able to select a file in that directory, click "ok", and store its information in variables without a ...

What is the process for adding text before and after a Bootstrap progress bar?

I want to customize the bootstrap progress bar with text at the beginning and end, like this: 5 star ----------------------------------------------- 70% Here is my attempt to achieve this: <link rel="stylesheet" href="https ...

Update the default monospaced font in Draft.js

Is it possible to change the default system monospace font in Draft Editor to Consolas using Draft.css or global css classes? ...

Customizing the appearance and dimensions of JWPlayer Audio Player with percentage-based styling

I'm currently attempting to set up an audio embed using JWPlayer, following the instructions provided in this particular article. The article suggests setting it up with the following code: <div id="myElement">Loading the player...</div> ...

An error occurred while trying to set the property 'IS_CHECK' of an object that is undefined

I'm attempting to create a checkbox that, when selected, should also select everything else. I followed the code example provided in this tutorial for angular 2. However, I encountered an error: "ERROR TypeError: Cannot set property 'IS_CHECK&ap ...

Ways to enlarge an image while hovering the mouse over it without disrupting the positions of other images (JQuery)

Is there a way to achieve a similar effect to Google Images, where the image pops and comes in front when we mouse over it without affecting the positions of other images? This should only happen when the cursor is still and not moving around randomly. I ...