Rearranging the stacking order of CSS pseudo-element

In the midst of creating a 3-stage progress bar using only CSS. The current design is displayed below:


               #progBar {
                   background-color:#bdbdbd;
                   padding:1.5vw;  
                   position:relative; 
                   height:9vw;
                }

                .progcapt {
                    background-color: #526cfd;
                    color: transparent;
                    text-shadow: 0px 2px 3px #526cfd; 
                    -webkit-background-clip:text;
                    font-family:'arial black';
                    font-size:3vw;
                 }

                 #cOne {
                     position:absolute;
                     left:calc(50% - 2.5vw);
                     top:calc(50% - 2.5vw);
                     border-radius:5vw;
                     height:5vw;
                     width:5vw;
                     border:1px solid #526cfd;
                     text-align:center;
                     display:flex;
                     align-items:center;
                     justify-content:center;
                     box-shadow:0px 0px 3vw #526cfd;
                     background-color:white;

                  }

                  #cOne::before {
                      position:absolute;
                      width:50vw;
                      height:1vw;   
                      background-color:rgba(82,108,253,0.5);
                      content:'';
                 }

                 #cOneRing {
                     position:absolute; 
                     top:-calc(0.5vw + 1px);
                     left:-calc(0.5vw + 1px);
                     width:6vw;
                     height:6vw;
                     border:1px solid #526cfd;
                     border-radius:6vw;
                  }
            
        
 
               <div id='progBar'>
                  <div id='cOne'>
                      <span class='progcapt'>1</span>
                      <div id='cOneRing'>&nbsp;</div>
                   </div>
              </div>
           
         

The purpose behind this design:

  • Three discs, each representing a step
  • The central disc serves as an "anchor"
  • An annular border is created for each disc by absolutely positioning it and nesting the annulus inside
  • A pseudo-element (::before) is used to create a track for the progress bar on the anchor
  • All components (circles and track) are placed within a relatively positioned rectangular bar acting as the background

The problem faced involves attempting to move the track behind its parent disc element using z-index="-1". Unfortunately, this causes it to vanish completely. It's apparent that I'm missing something crucial, but unable to pinpoint the issue. Hopefully, someone can help identify the error.

Answer №1

It seems like you are in need of the following code snippet:

#progBar {z-index: -2;}
#cOne::after { z-index: -1;}

    #progBar
    {
    z-index: -2;
     background-color:#bdbdbd;
     padding:1.5vw;  
     position:relative; 
     height:9vw;
    }
    .progcapt
    {
     background-color: #526cfd;
     color: transparent;
     text-shadow: 0px 2px 3px #526cfd; 
     -webkit-background-clip:text;
     font-family:'arial black';
     font-size:3vw
    }
    #cOne
    {
     position:absolute;
     left:calc(50% - 2.5vw);
     top:calc(50% - 2.5vw);
     border-radius:5vw;
     height:5vw;
     width:5vw;
     border:1px solid #526cfd;
     text-align:center;
     display:flex;
     align-items:center;
     justify-content:center;
     box-shadow:0px 0px 3vw #526cfd;
     background-color:white;

    }
    #cOne::before
    {
     position:absolute;
     width:50vw;
     height:1vw;   
     background-color:rgba(82,108,253,0.5);
     content:'';
     z-index:-1; 
    }
    #cOneRing
    {
     position:absolute; 
     top:-calc(0.5vw + 1px);
     left:-calc(0.5vw + 1px);
     width:6vw;
     height:6vw;
     border:1px solid #526cfd;
     border-radius:6vw;
     
    }
     <div id='progBar'>
        <div id='cOne'>
         <span class='progcapt'>1</span>
         <div id='cOneRing'>&nbsp;</div>
        </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

Using JavaScript to add a class when hovering over an element

I am trying to customize the ul inside one of my li elements in the nav by adding a class when hovered. However, I am encountering an issue where the menu disappears when I try to click on it after hovering over it. I want to achieve this functionality usi ...

Is there a way to modify the location of the datepicker/calendar icon within my bootstrap form?

When using react-bootstrap with the <Form.Control type="date"> element, I noticed that the calendar icon or date picker is automatically positioned to the right side/end of the form field. However, I am interested in moving the calendar ico ...

Using Vuetify: adding an asterisk to indicate required fields

The most recent update of Vuetify (v1.3 - ) has brought a significant change. Now, the asterisk is no longer automatically added to the label when using v-textarea/v-text-field with the required prop.. You will need to include it manually in the label pro ...

Having trouble with aligning text using the span tag?

I'm attempting to create a line for pricing where the text-align is aligned differently for each item - left, center, and right. Despite using text-align, I am unable to maintain all three items on the same line. Is there an alternative solution or w ...

What is the best way to align items in the Bootstrap navbar?

I attempted to center elements within a Bootstrap 5 navbar using a Vue template, but neither display flex with justify content: center nor text-center worked for me. I also tried applying align-items to the elements without success. My goal is to have th ...

Move the Div element up and down when clicked

When a tag is clicked, the corresponding div opens and closes. I would like the div to slide down and up slowly instead of appearing immediately. <a href="" class="accordion">Click here</a> <div class="panel" id="AccordionDiv"> ...

Out-of-stock contact form button for WooCommerce

Our webshop needs a button added to every out-of-stock product page. I've tried adding the code below, but the button appears on all products, including those that are in stock. Can someone provide guidance on how to fix this issue? Appreciate any he ...

Applying ng-class based on conditions to icons within table cells

In my table, I am using ng-repeat to bind cells with data. One cell contains edit, save, and delete icons. When an order is posted, the delete/save icons should be disabled and displayed in a different color. While I can disable the click event of the icon ...

Let's apply some CSS to the font style within the body

I've been incorporating a "footer.php" page into all other pages of my website. This footer showcases the site's name at the bottom of the screen and uses a custom font loaded with @font-face. Initially, I had something like this placed inside t ...

Sticky box fails to maintain position as header scrolls

I am looking to create a Sidebar that sticks to the window while scrolling, but stops when it reaches the footer. I have managed to get it partially working, but there is a small issue that I can't seem to solve. Test it live here: Everything seems ...

Utilize CSS properties to pass as arguments to a JavaScript function

Is there a way for me to make my CSS animation functions more efficient? I have similar functions for different properties like height, width, and left. Can I modify the function below to accept a CSS property argument instead of hardcoding height? Window ...

Resolving background div alignment issue in ASP.NET

I am facing a rather straightforward issue that requires resolution. I am currently working on fixing a background div (<div class="main-background">) that contains an image on my webpage. While it displays correctly in Design View in Visual Studio, ...

Building a website using Bootstrap: A step-by-step guide

Wondering how I can incorporate all the cool Bootstrap components into a webpage. Is there a tool that offers live preview? Back in the day (web 1.0), Dreamweaver was my go-to for creating HTML and basic CSS, but what are some current tools where I can si ...

When elements are passed through components in Next.js, their style does not get applied

I have a unique component for the hero section of every page with varying content and heights. export default function CustomHero({ height, children, }: { height: string; children: ReactNode; }) { return ( <div className={`flex flex- ...

How can you generate an HTML table row without using the <tr>

Greetings everyone! I am currently working on creating a table using HTML, Bootstrap 5, and CSS to display various article details. Each article may have one or multiple variants, and I would like these variants to be displayed as rows within the parent ar ...

Ways to conceal Bootstrap-designed elements behind a fullscreen overlay

I'm attempting to create a transparent layer to conceal the entire content of my page behind it. It works fine without the Bootstrap columns, but as soon as I add the columns for responsive design, it stops working (or maybe I'm just not understa ...

How to implement responsive CSS in Laravel 4

It has come to my attention that in Laravel 4, you can load CSS and scripts using the following method: {{ HTML::style('css/style.css'); }} Which will result in: <link media="all" type="text/css" rel="stylesheet" href="http://localhost/cupc ...

Adjust the DIV dimensions to fit the background image perfectly

My question involves a DIV element with a specific style applied to it. .vplayer-container .logo { position: absolute; bottom: 50px; right: 10px; background: url(../img/logo.png) no-repeat; border: 1px solid #000000; max-width: 50px; max-height: 50 ...

Ways to eliminate the default button styling

I've encountered an issue with the CSS for a button that I created, as it is not displaying as expected. https://i.sstatic.net/qHLZX.png Below is my HTML code snippet: .button{ /* center the button */ margin: 0; position: absolute; top: ...

How can one determine the proper size for a border?

Can the border of a div be larger than the actual dimensions of the div itself? For instance, if the div is 10x10 in size, is it possible to have a border that is 20x10? ...