Static element causing z-index conflict

https://jsfiddle.net/0Lfzbzc5/2/

My current challenge involves positioning the notification box on top of the body class div, but I am encountering some difficulties. The logic dictates that positioned elements should be displayed on top of non-positioned elements, however, this is not occurring as expected.

I even attempted to make the body class div relative and assign it a z-index value, but unfortunately, this approach also failed. The structure of the notification box consists of an absolute element within a relative element inside another absolute element (required for CSS animation purposes).

HTML

<div class="notiIcon glyphicon glyphicon-globe">
</div>
<div class='notiAbs '>
    <div class='notiContainer'>
        <div class="notiBox">
            <div class="notiHeader">
                <span class="notiHeaderSpan">notifications</span>
            </div>
            <div class="notiBody">
                <div class="notiElement">Collaboratively enable high-quality imperatives before ubiquitous paradigms.
                </div>
                <div class="notiElement">Credibly productize customized services whereas.</div>
                <div class="notiElement">Efficiently embrace real-time markets without.</div>
                <div class="notiElement">Synergistically simplify collaborative web services.</div>
                <div class="notiElement">Intrinsicly evisculate magnetic e-services through.</div>
                <div class="notiElement">Holisticly build customer directed technologies.</div>
                <div class="notiElement">Phosfluorescently synthesize team driven strategic.</div>
            </div>
            <div class="notiFooter"><span class="notiHeaderSpan">See All</span></div>
        </div>

    </div>
</div>
<div class="body">aasdasdasdasdasdasdas</div>

CSS

.notiAbs{
    position: absolute;
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
    /* overflow-y: hidden; */
    height: 500px;
    width: 500px;
    /* overflow-x: hidden; */
    overflow-y: hidden;
       margin: 0 auto;
    padding-left: 50px;

}
.notiContainer{
    position: relative;
}
.notiIcon{
    z-index: 5;
    position: relative;
    width:100%;
    text-align: center;
        font-size: 25;
    cursor: pointer;
    padding-top: 10px;

}
.notiIconNumber{
    position: relative;
    font-size: 15px;
    color: white;
    background-color: red;
    top: -10;
    left: -9;
    padding: 2px;
}
.notiBox{
    z-index: 4;
    position: absolute;
    height: 400px;
    width: 400px;
    display: block;
    padding-top: 10px;
    box-shadow: rgba(0, 0, 0, 0.298039) 0px 4px 7px;

}
.notiElement{
    overflow-wrap:break-word; 
    font-size: 17px;
    padding: 10 0px;
    border-bottom-style: solid;
    border-bottom-width: thin;
    border-bottom-color: lightgray;
}
.notiHeader,.notiFooter{
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    height: 15%;
    display: table;
    width: 100%;
}
.notiHeaderSpan,.notiFooterSpan{
    display: table-cell;
    vertical-align: middle;
}
.notiFooter{
        box-shadow: 0px -4px 7px rgba(0, 0, 0, 0.1);
        cursor: pointer;
}
.notiHeader{
    box-shadow: 0px 4px 7px rgba(0, 0, 0, 0.1);
}
.notiBody{
        padding: 20px;
        overflow: auto;
        height:70%;
}
.body{
}

Answer №1

The element appears at the top of the page, but its background is transparent, creating the illusion that it's not actually there. To make it visible, simply add a background color using the following CSS:

.notiBox{
    z-index: 4;
    position: absolute;
    height: 400px;
    width: 400px;
    padding-top: 10px;
    border-style:solid;
    background:#666;

}

For a live example, check out the Fiddle.

Answer №2

The notification box that you are referring to, identified by the class "notiBox," may seem like it is not on top due to its inherited background-color of transparent.

By changing the background-color property to something like "yellow," you will notice that it actually appears on top of the element with the class "body."

If this concept is still unclear, feel free to ask for further clarification.

After reviewing your HTML once again, it seems that the element with the class "notiBox" and its contents are the only ones you want to display on top.

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

Tips for invoking a function to automatically load elements on a jQuery mobile website

I am looking to keep my navbar HTML markup in a centralized location for easy editing. Currently, the body content of my index.html file appears like this: <div data-role="page" id="SomePage"> <div data-role="header"> <h1>Thi ...

Alter the color of the initially chosen option in the dropdown selection

I'm struggling to modify the color of the initial selection while keeping the remaining selection-options at their default black color. Unfortunately, I haven't been successful in achieving this. Currently, all colors are #ccc. What I want is fo ...

The search and sorting functionality in jquery DataTables is malfunctioning

I am facing difficulties with sorting and filtering the datatable as none of the JS functions seem to be working properly. I have already included the necessary JS files. Here are some details: I am connecting to a database to retrieve data in JSON format. ...

The craft of masonry is known for its creation of intentional gaps

I've gone through all the posts related to this issue, but none of the suggested solutions seem to work for me. Here is a visual representation of my grid: https://i.sstatic.net/ybufk.png If you want to see the code and play around with it, check o ...

Choose an image and save the selection information for the following page (Tarot card)

I'm in the process of creating a website that showcases multiple tarot cards. The goal is for users to select the cards they're interested in and have their chosen card displayed on the next page. I've implemented some code for selecting the ...

A pop-up appears, prompting me to redirect to an external URL when clicking on a link that opens in a new tab on my WordPress website

Seeking assistance in dealing with a popup that appears when trying to open a link redirected to an external URL. The popup prompts for permission to open the link in a new tab. Upon inspecting the Element, the code snippet below is revealed: <div cla ...

Issue with forms not correctly transferring data from selected checkboxes

I am attempting to submit all checked input checkboxes. The input fields are dynamically generated through a Django loop. Based on my research, the code below should be functional. I suspect that the issue lies in the generation of input fields within the ...

Display endless data within a set window size

I am looking to create a fixed-size window for displaying text from the component <Message/>. If the text is longer, I want it to be scrollable within the fixed window size. See screenshot below: Screenshot export default function AllMessages(){ ...

Having difficulty retrieving the value from a database column as it consistently displays both the column name and value

I am currently working on setting up a dynamic site title that will be controlled by my database. This way, I can easily update the database with a new title and have it reflect on my website. Below is an example of the controller setup: TestController: ...

"Hover over the image to see it enlarge and reveal text displayed on top using CSS3

I have been working on creating a responsive image page for my website. I've managed to make the images responsive and centered, no matter the size of the browser window. However, I encountered an issue where when I hover over an image, it enlarges a ...

Ordering styles in Material UI

I've spent countless hours customizing this element to perfection, but the more I work on it, the more of a headache it gives me. The element in question is an outlined TextField, and my focus has been on styling its label and border. Initially, I th ...

The Hidden Div containing NicEdit is now shrunk down to a smaller size

Attempting to integrate the NicEdit editor for a hidden textarea stored within a div has presented some challenges. The goal is for the targeted textarea's parent div to be revealed upon the user clicking a button, with the textarea's width set t ...

Tips for aligning a drop down list in the center

I need help center-aligning my dropdown list to match the buttons that are also center-aligned. Do you have any suggestions on how I can achieve this using .css? <h4 id="carbCount" class="pageElement">The Carb Count is 0</h4><br /> &l ...

How to apply an icon image using the background property in CSS in Vue 3

Need help setting background image from the public folder |_public | |_images | |_icon.png |_src |_components |_TheHeader.vue I'm having difficulty trying to set an image as a background in TheHeader.vue using CSS, but the image is located in ...

Collaborate on documents with fellow users on the Django platform

Summary of the app: The main focus of this application is to enable users to create projects and share uploaded files with others, based on permission settings. Basically, after creating a project using the Project module, when a user uploads a file to the ...

Populate HTML Table with Array Elements

I need assistance with inserting array values into an HTML table. The table should have 5 columns and enough rows to accommodate all the information. I envision it looking like this: 1 | 2 | 3 | 4 | 5 11 | 22 | 33 | 44 | 55 111 | 222 | 333 | 444 | 555 ...

Add to the end just before the final element when generating dynamically

var creatediv = document.createElement("div"); var text1 = '<input id="attribute1" type="text" placeholder="Attribute" /> $(creatediv).append(text1); var text3 = '<input id="attribute3" type="text" placeholder="Attribu ...

Having trouble with the mouse trail code on codepen.io

I am currently attempting to integrate this specific CodePen sample into a Hugo template called Somrat Theme. I'm facing challenges in deciding where to place the HTML file; only the 'no cursor' section should go into style.css, and I need ...

Having trouble displaying an image using output buffering in PHP and HTML, only to end up with a broken image

I've been working on a script that combines two PNG images - one as a watermark and the other as the source image. The idea is to blend these images together using the imagecopy function and display the result in the browser. However, despite my effor ...

When the enter key is pressed, the anchor tag does not function properly after setting the tabindex value to "0" for the surrounding div element

Having an issue with Safari not focusing on my anchor element. I added tabindex="0" around the div to address this, but now the link doesn't work when pressing enter in any browser. Am I missing something here? <div class="used__button&quo ...