Creating an attention-grabbing alert bar positioned above the menu

When I attempted to add this alert bar to my website, I encountered an issue where it was being hidden behind my menu. Some sources suggest that using z-index and position:absolute can resolve this problem by positioning one element above the other, but this did not work in my case. I am seeking advice on how to place the alert bar over the menu. Any assistance would be greatly appreciated.

Here is a demo that showcases the problem.

CSS:

body {
    padding: 0;
}

/* Alert Bar */

#alert {
    position: relative;
}
#alert:hover:after {
    background: hsla(0,0%,0%,.8);
    border-radius: 3px;
    color: #f6f6f6;
    content: 'Click to dismiss';
    font: bold 12px/30px sans-serif;
    height: 30px;
    left: 50%;
    margin-left: -60px;
    position: absolute;
    text-align: center;
    top: 50px;
    width: 120px;
}
#alert:hover:before {
    border-bottom: 10px solid hsla(0,0%,0%,.8);
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    content: '';
    height: 0;
    left: 50%;
    margin-left: -10px;
    position: absolute;
    top: 40px;
    width: 0;
}
#alert:target {
    display: none;
}
.alert {
    background-color: #c4453c;
    background-image: linear-gradient(135deg, transparent, transparent 25%, hsla(0,0%,0%,.05) 25%, hsla(0,0%,0%,.05) 50%, transparent 50%, 
                    transparent 75%,hsla(0,0%,0%,.05) 
                    75%);
    box-shadow: 0 5px 0 hsla(0,0%,0%,.1);
    color: #f6f6f6;
    display: block;
    font: bold 16px/40px sans-serif;
    height: 40px;
    position: absolute;
    text-align: center;
    text-decoration: none;
    top: -45px;
    width: 100%;
    animation: alert 1s ease forwards;
}

/* Animation */

@keyframes alert {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { top: 0; }
}

/* Menu */

#cssmenu {padding: 0; margin: 0; border: 0;}
#cssmenu ul, #cssmenu li {list-style: none; margin: 0; padding: 0;}
#cssmenu ul {position: relative; z-index: 597;}
#cssmenu ul li {float: left; min-height: 1px; vertical-align: middle;}
#cssmenu ul li.hover,
#cssmenu ul li:hover {position: relative; z-index: 599; cursor: default;}
#cssmenu ul ul {visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598;}
#cssmenu ul ul li {float: none;}
#cssmenu ul ul ul {top: 0; left: auto; right: -99.5%;}
#cssmenu ul li:hover > ul { visibility: visible;}
#cssmenu ul ul {bottom: 0; left: 0;}
#cssmenu ul ul {margin-top: 0;}
#cssmenu ul ul li {font-weight: normal;}
#cssmenu a { display: block; line-height: 1em; text-decoration: none; }

#cssmenu {
  background: #333;
  border-bottom: 4px solid #1b9bff;
  font-family: 'Oxygen Mono', Tahoma, Arial, sans-serif;
  font-size: 12px; 
}

HTML:

<div id="alert">
    <a class="alert" href="#alert"> Alert Bar overlapped</a>
</div>

<div id='cssmenu'>
  <ul>
     <li class='has-sub '><a href="#">XXX</a>
     <ul>
     <li><a href="#">XXX</a></li>
     <li><a href="#">XXX</a></li>
     <li><a href="#">XXX</a></li>
     <li><a href="#">XXX</a></li> 
     <li><a href="#">XXX</a></li>          
 </ul>
</li>
     <li class='has-sub '><a href="#">XXX</a>
        <ul>
           <li><a href="#">XXX</a></li>
           <li><a href="#" class="messages">XXX</a></li>                              
           <li><a href="#">XXX</a></li> 
           <li><a href="#" class="documents">XXX</a>
           <ul>
              <li><a href="#" class="documents">XXX</a></li>
              <li><a href="#" class="documents">XXX</a></li>
           </ul>
         </li>
      </ul>
     </li>           
     <li><a href="#">XXX</a></li>
   <li class='has-sub'><a href="#">XXX</a>
      <ul>
         <li><a href="#">XXX</a></li>

      </ul>
   </li>
     <li><a href="#">XXX</a></li>

  </ul>
</div>

Answer №1

Update the z-index to a new value of 9999

#alert {
    position: relative;
    z-index: 9999;
}

Answer №2

I've identified the issue - it's within your code.

You originally set the #alerts div with a z-index:100, but at some point in your code, you also defined #cssmenu ul {z-index:549} or something greater than 100. To resolve this problem, simply update the #alert `z:index:1000' and you'll be good to go.

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 keeping notification icons in the upper right corner of the box?

I am facing an issue with absolute positioning where the notification icons I've positioned to the top-right corner of a box are moving away when the screen size changes. Desired appearance of the image Actual appearance when screen size is adjusted ...

How can I trigger the appearance of the navigation bar when reaching the second div while scrolling

Is there a way to make the navigation bar appear only when a user has scrolled down to the second div on the page? The first div is the header. I am wondering how this can be achieved using jQuery? <!DOCTYPE html> <html> <head> <me ...

How can I make a Material UI element fill the entire remaining width of the Grid?

Is there a way to make the child element take up the remaining width of the grid in Material UI? I am trying to have the "User Name" text field fill up the rest of the space in the grid cell but so far I have not been successful. I have even attempted us ...

Is there a way to restrict my input to only 10 numbers without allowing any characters?

Is there a way to restrict the phone number input to only allow 10 numbers and exclude any other characters? Currently, setting the maxLength attribute limits the characters to 10 but allows additional characters as well. If I change the type attribute to ...

Easiest method to change cursor to 'wait' and then return all elements to their original state

On my website, there are certain CSS classes that define a specific cursor style when hovered over. I am trying to implement a feature where the cursor changes to a "wait" image whenever an AJAX call is initiated on any part of the page, and then reverts b ...

Transforming data from an HTML table into a MySQL database

Is there a way to transfer data from an HTML table created with JavaScript to a SQL database? I have been experimenting with the addRow(tableID) function but it doesn't seem to work. Any suggestions on how to solve this issue? Below is the code snipp ...

Tips for showcasing overflowing text in a menu list by rotating the item text

Imagine you have a TextMenuItem component, using MenuItem from the Material-UI library, that is part of a chain consisting of DropDownSearch > SimpleListMenu > FixedSizeList > TextMenuItem. In simple terms, this creates a searchable dropdown element with t ...

Transforming HTML Code in a PHP Document to a PDF Document

I have a PHP file that interacts with a database to update the HTML content. There is a button on the page labeled "Export As PDF". I attempted to convert the page to a PDF using HTML2FPDF, but encountered this error message: FPDF error: Unable to create ...

Mastering the CSS Art of Working with Sprite Images and Their Positioning

I am currently working on an educational project as a front-end developer, where I aim to clone the Google homepage. To achieve this, I am utilizing Google's own sprite and here is the image of the sprite that I am using. https://i.stack.imgur.com/YT ...

What could be causing transition to not be recognized as an element in HTML?

<template> <header> <nav class="container"> <div class="branding"> <router-link class="header" :to="{name : 'Home'}">>FireBlogs</router-link> </div& ...

Determining whether an element possesses an attribute labeled "name" that commences with a specific term, apart from the attribute "value"

I'm planning to use distinctive data attributes with a prefix like "data-mo-". Let's say I have the following elements: <span data-mo-top-fade-duration="600">Title 1</span> <span data-mo-bottom-fade-duration="600">Title 2</ ...

Implement a background image in the navigation bar links using CSS

Strange as it may seem, the image refuses to show up in the navbar. Adding borders or other styling makes it visible, but not the image itself. If I manually include the image using the <img/> tag in the HTML, it appears, but then the hover effect do ...

Showing Predefined Date on an HTML Form in an iOS Application

Is there a method to dynamically show the current date within the button that triggers the date picker in an HTML form on an iOS device? This is what currently appears: This is what I want it to automatically display: Below is the code I have implemente ...

css background images are fully covered

Hey there! I recently created a CSS image that covers the entire background of my website. However, when I added a picture in the HTML, it doesn't show up because it's being overlapped by the CSS background. Check out my CSS code: { margin: 0 ...

Struggling to float <aside> to the left of <article> for proper alignment?

tldr; I'm attempting to position the aside-section to the left of the article-section (similar to a sidebar/side column), but my "float" property doesn't seem to be working at all. Is there a way to achieve this without modifying the HTML code an ...

What is the best way to effectively incorporate Ruby into the CSS attribute of a HAML %li element?

Greetings everyone, I am new to the world of development and seeking guidance from experienced individuals. I have been trying to solve a coding issue for quite some time now. I am currently enrolled in a programming course at Code Academy based in Chicago ...

A specific class has no border on its left side

Is there a way to use CSS to disable the left border to the right of a cell with a specific class? In the scenario shown in this image, the right border appears double due to the combination of the "selected" class border and the default gray border. I wo ...

Achieve an overlapping effect between absolutely positioned sibling divs without the need to specify a background color

Exploring the development of a swipe-to-action list component. <div class="list-container"> <div class="row"> <div class="content"> Sample Content 1 </div> <div class="action"> ...

JavaScript Document Object Model: Locate an element with a class that is either similar to or includes a specific substring

I am facing a situation where I need to locate a wrapper element with a specific class name that includes a random id, such as wp-rgtayfu-fxyjzw-wrapper. The class will always have the substring wrapper in it, and there is only one element in the document ...

Subject line matches webpage header

Is it possible to automatically generate an email subject that includes the title of the webpage from where the user is sending an email? For instance: If my webpage's title is "About Us," Can the email subject be "About Us" as well? I am not very ...