Rearrange elements by swapping based on their z-index and layer order

Trying to design a unique CSS effect where there is a fixed colored element in the top left corner of a webpage. The background consists of different stages or chunks (red, green, blue) each with a height of 1000px. I want the color of the icon to transition at each "bridge" between these stages. Visualizing two halves of fixed elements overlapping to create one cohesive unit.

View my mockup on jsfiddle

Check out the CSS below:

.stage{width:100%;height:1000px;position:relative;}
.stage.one{background:red;z-index:1;}
.stage.two{background:green;z-index:1;}
.stage.three{background:blue;z-index:1;}

.box{width:50px;height:50px;position:fixed;margin:10px;}
.box.one{background:purple;z-index:1;}
.box.two{background:orange;z-index:1;}
.box.three{background:yellow;z-index:1;}

Now onto the HTML code:

<div class="box one"></div>
<div class="box two"></div>
<div class="box three"></div>

<div class="stage one">
    <div class="box one"></div>
</div>

<div class="stage two">
    <div class="box two"></div>
</div>

<div class="stage three">
    <div class="box three"></div>
</div>

Looking for a CSS-only solution here, avoiding JavaScript to push the limits of what can be achieved solely through styling.

Answer №1

Check out the demo

Using only CSS to achieve this task is not feasible due to certain limitations. Initially, when you style elements like .stage.one (red), .stage.two (green), and .box.one (purple), you configure them in a way that positions the purple box on top of the red one and below the green one. This setup creates a deadlock situation where it becomes impossible to insert another box above purple, beneath red, and on top of green simultaneously.

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

How do I utilize AJAX and HTML to invoke a RESTful web service in Java?

How to call a RESTful webservice in Java using HTML Ajax? I have created a simple webservice in Java and want to POST data into a database using HTML Ajax by calling a Java webservice in Eclipse. However, I encountered an error in my Java program. How can ...

Using *ngFor to display the initial element from an array

Here is the code I am currently using: <div *ngIf="gamedata.notOver" class="columns"> <div class="column has-text-centered" *ngFor="let board of boards; let i = index"> <table class="is-bordered" [styl ...

The route seems to be downloading the page instead of properly rendering it for display

I'm facing a simple issue with my Express page - when I navigate to the FAQ route, instead of displaying the page it downloads it. The index page loads fine, and the FAQ page is the only other page available at the moment. I am using EJS templating, a ...

Do you have any tips on designing a mobile-friendly navigation bar?

Struggling with creating a responsive navbar using Bootstrap 5? The navbar-brand is causing issues with letters overflowing over other elements, and the toggle-icon is not aligning properly. Check out my Codepen for reference: https://codepen.io/namename12 ...

Adjust the height of each child element to be half of the fixed height of the parent

There is a wrapper containing multiple boxes generated using ng-repeat from a list. The wrapper has a fixed height of 300px. If the list contains only one box, a class is added to fill the entire space of the wrapper. However, when there are more than on ...

Incorrect Size of Image in Srcset Rendering

I'm in the process of implementing responsive and adaptive images based on device width. Here is the original image: <img src="https://cdn.statically.io/img/www.forexadmin.com/wp-content/uploads/2019/11/Exness-Affiliate.png"/> Using Srcset: ...

Have you considered showcasing all images in a carousel format?

I have a total of 6 picture blocks, but only the first 3 images are displayed in the carousel. I suspect there may be an issue with jQuery, but I'm unsure where to look. Any hints or guidance would be greatly appreciated. Thank you! Below are the blo ...

Every div must have at least one checkbox checked

Coding in HTML <div class="response"> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> </div> <div class="response"> <input type="check ...

HTML: How come the EventListener isn't refreshing the Button?

I am attempting to create a field that displays the count of selected (highlighted) characters. However, I am encountering an issue where it does not work as intended. Specifically, the line document.getElementById('selectedCountBtn').textContent ...

"Can anyone tell me why my index.html file isn't recognizing the style.css file located in my css directory

In the directory structure below, I have the following files: mywebsite/ ├── css/ │ ├── style.css │ ├── index.html This is my HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

The tab navigation feature is experiencing issues in Internet Explorer versions 7 and 8

I have successfully implemented a tab menu that functions well in Chrome and IE 9,10. However, it does not seem to work in IE 7 or 8. I am at a loss regarding what changes need to be made to my code. Could anyone provide assistance? Link to Code Example ...

Modify table row background color using PHP based on its position in the table with the use of a function

I am having trouble formatting my table to highlight different rows in distinct colors. The top row should be one color, the second row another, and the bottom two rows a different color each. This is to represent winners, teams getting promoted, and tho ...

What is the best way to conceal the border and background color of the dropdown arrow in an HTML <select> tag?

Upon browsing the Mozilla homepage, I noticed a peculiar element in the center - a <select> option with an arrow lacking border and background color. In contrast, when visiting the Facebook sign-up page, the drop-down arrow adheres to the Windows sta ...

Whenever I attempt to style a html/jsx tag in css, I receive an error message stating that 'h1 "selector" is not pure'

Issue: The CSS selector "h1" is not considered pure (pure selectors must include at least one local class or id) 5 | } 6 | > 7 | h1 { | ^ 8 | font-size: 48px; 9 | text-align: center Encountered this error while attempting ...

AngularJS: Issue with scope not updating across several views

Having one controller and two views presents a challenge. ClustersController angular.module('app.controllers').controller('ClustersController', [ '$scope', 'ClustersService', function($scope, ClustersService) { ...

What are the steps for transitioning with JavaScript?

My goal is to make both the <hr> elements transition, but I'm struggling with only being able to select the lower <hr> using CSS. html { margin-bottom: 0; height: 100%; min-height: 100%; } body { margin-top: 0; height: 100%; ...

Clip the text with ellipsis if it exceeds the limit and show the file

Currently working on an upload feature where I need to show the name of the uploaded file. File Name.txt The problem arises when the name is too lengthy, resulting in a display like this: File Name Is Too Long...txt I attempted to solve this by implement ...

I'm looking for assistance on how to set the minimum height using jQuery. Can anyone provide

My attempt to use the minHeight property in one of my divs is not successful, and I am unsure why... <div id="countries"> <div class="fixed"> <div class="country" style="marging-left:0px;"></div> <div class="country"&g ...

How to choose a particular Excel spreadsheet in Angular before importing the file?

I am currently working on a new feature that allows users to choose a specific Excel worksheet from a dropdown list before importing a file. However, I am facing some difficulty in adding the worksheet names to the dropdown list. Right now, I have placehol ...

Is it possible to integrate HTML into PHP code without using echo statement?

On my index page, I wanted PHP to verify if the user is logged in when it loads. If the user is logged in, the webpage content would be displayed. If not, it would show the login page for the user. Here is the PHP code for the check: <?php if ($_SESSI ...