Display tooltips on top of z-index stacking contexts

I am struggling to display a tooltip within a table field, on top of other fields and tables. The issue lies in the fact that the other tables and elements are housed within different DIVs that have set the CSS z-index property to 0.

Even if I assign a high value (e.g. 9999) to the tooltip's CSS z-index property, it still appears behind the other tables due to z-index stacking contexts.

I want to avoid modifying the z-index property of the other elements since I am inserting my elements into a third-party web page.

Furthermore, moving the tooltip to a higher level is not an option as I want it to be automatically removed when the element containing the tooltip is dynamically removed by the third party.

Is there a CSS solution to this conundrum?

You can experiment with the situation using this JSFiddle: https://jsfiddle.net/u6q8j4ck/

.content {
  position: relative;
  display: block;
  margin-top: 10px;
  margin-bottom: 10px;
  z-index: 0;
}

table {
  position: relative;
  background: #ccc;
}

table td {
  white-space: nowrap;
}

table td span {
  position: relative;
  display: inline-block;
}

.hoverable {
  position: relative;
  display: inline-block;
  white-space: nowrap;
}

.hoverable img {
  display: inline-block;
  width: 15px;
}

.tooltip {
  position: absolute;
  display: none;
  z-index: 9999;
  padding: 5px;
  background-color: white;
  white-space: nowrap;
  border-style: solid;
  border-width: 1px;
}

.hoverable:hover .tooltip{
  display: block;
}
<html>
<body>
    
    <div class="content">
        
          <table border>
          <tbody>
            <tr>
              <td>
                <span>Hover this:</span>
                <div class="hoverable">
                  <img src="https://img.icons8.com/flat_round/344/info.png">
                  <div class="tooltip">
                    <span>I am on TOP of the tables?</span>
                    <ul>
                      <li>List 1</li>
                      <li>List 2</li>
                    </ul>
                  </div>
                </div>
              </td>
              <td>Table Text</td>
              <td>Table Text</td>
            </tr>
          </tbody>
          </table>
          
          <div>
            <span>Content text</span>
          </div>
          
    </div>
    
    <div class="content">
        
          <table border>
          <tbody>
            <tr>
              <td>
                <span>Hover this:</span>
                <div class="hoverable">
                  <img src="https://img.icons8.com/flat_round/344/info.png">
                  <div class="tooltip">
                    <span>I am on TOP of the tables?</span>
                    <ul>
                      <li>List 1</li>
                      <li>List 2</li>
                    </ul>
                  </div>
                </div>
              </td>
              <td>Table Text</td>
              <td>Table Text</td>
            </tr>
          </tbody>
          </table>
          
          <div>
            <span>Content text</span>
          </div>
          
    </div>
    
    <div class="content">
        
          <table border>
          <tbody>
            <tr>
              <td>
                <span>Hover this:</span>
                <div class="hoverable">
                  <img src="https://img.icons8.com/flat_round/344/info.png">
                  <div class="tooltip">
                    <span>I am on TOP of the tables?</span>
                    <ul>
                      <li>List 1</li>
                      <li>List 2</li>
                    </ul>
                  </div>
                </div>
              </td>
              <td>Table Text</td>
              <td>Table Text</td>
            </tr>
          </tbody>
          </table>
          
          <div>
            <span>Content text</span>
          </div>
          
    </div>

</body>
</html>

Answer №1

It appears that there might be a solution to the problem by utilizing one of the techniques outlined in Temani Afif's linked answer:

.content {
  position: relative;
  display: block;
  margin-top: 10px;
  margin-bottom: 10px;
  z-index: 0;
}

table {
  position: relative;
  background: #ccc;
}

table td {
  white-space: nowrap;
}

table td span {
  position: relative;
  display: inline-block;
}

.hoverable {
  position: relative;
  display: inline-block;
  white-space: nowrap;
  transform-style: preserve-3d;
}

.hoverable img {
  display: inline-block;
  width: 15px;
}

.tooltip {
  position: absolute;
  display: none;
  z-index: 9999;
  padding: 5px;
  background-color: white;
  white-space: nowrap;
  border-style: solid;
  border-width: 1px;
  transform: translateZ(1px);
}

.hoverable:hover .tooltip{
  display: block;
}
<html>
<body>
    
    <div class="content">
        
          <table border>
          <tbody>
            <tr>
              <td>
                <span>Hover this:</span>
                <div class="hoverable">
                  <img src="https://img.icons8.com/flat_round/344/info.png">
                  <div class="tooltip">
                    <span>I am on TOP of the tables?</span>
                    <ul>
                      <li>List 1</li>
                      <li>List 2</li>
                    </ul>
                  </div>
                </div>
              </td>
              <td>Table Text</td>
              <td>Table Text</td>
            </tr>
          </tbody>
          </table>
          
          <div>
            <span>Content text</span>
          </div>
          
    </div>
    
    <div class="content">
        
          <table border>
          <tbody>
            <tr>
              <td>
                <span>Hover this:</span>
                <div class="hoverable">
                  <img src="https://img.icons8.com/flat_round/344/info.png">
                  <div class="tooltip">
                    <span>I am on TOP of the tables?</span>
                    <ul>
                      <li>List 1</li>
                      <li>List 2</li>
                    </ul>
                  </div>
                </div>
              </td>
              <td>Table Text</td>
              <td>Table Text</td>
            </tr>
          </tbody>
          </table>
          
          <div>
            <span>Content text</span>
          </div>
          
    </div>
    
    <div class="content">
        
          <table border>
          <tbody>
            <tr>
              <td>
                <span>Hover this:</span>
                <div class="hoverable">
                  <img src="https://img.icons8.com/flat_round/344/info.png">
                  <div class="tooltip">
                    <span>I am on TOP of the tables?</span>
                    <ul>
                      <li>List 1</li>
                      <li>List 2</li>
                    </ul>
                  </div>
                </div>
              </td>
              <td>Table Text</td>
              <td>Table Text</td>
            </tr>
          </tbody>
          </table>
          
          <div>
            <span>Content text</span>
          </div>
          
    </div>

</body>
</html>

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

Conceal the sidebar menu by clicking anywhere outside of the menu bar or the designated button

I attempted to create a menu similar to the semantic UI, but so far I have only been able to click the menu button to open and close the menu. I am using a toggle class to display the sidebar, but I'm unsure if this approach is entirely correct: < ...

I am looking to showcase a series of icons linked together by connecting lines

I have successfully designed the layout and added icons, but I am facing difficulty in creating connecting lines between them. I attempted to utilize CSS borders and pseudo-elements, yet I cannot achieve the desired outcome. If anyone could offer a CSS-ba ...

Positioning divs next to each other in CSS and setting the width of the second

I am attempting to position two divs next to each other. The initial one is 200x200 pixels and the second one should be positioned 10 pixels to the right of the first one. The second div has a height of 200 pixels, and its width needs to extend all the way ...

Choosing jQuery elements based on multiple criteria

My attempt at a seemingly simple task is proving to be quite confusing and isn't functioning as expected... The goal is clear - upon document load using $(document).ready(), I want to target all input elements with the attribute type="text" and apply ...

Displaying outcomes in dialog box when button is pressed

I am working on a website where I want to enhance the user experience by displaying output in a dialogue box upon click. The current setup involves the user selecting a vendor and time duration, with the results appearing below the Submit button. However, ...

Achieving Center Alignment of Two Elements with Varying Widths in Relation to the Parent Container, all while maintaining Left Alignment and consistent indentation

I am currently working with Material UI, but maybe this is just a matter of understanding how to achieve it with Flexbox. Something similar to what is shown in the image below. I am struggling to make all three lines align in the same way on different scre ...

Challenges encountered when integrating images with Bootstrap's grid system

I have implemented a simple Grid System to create a small "Portfolio" showcasing images (4 columns and roughly 6 rows), however, the display looks like this <div class="container"> <div class="row"> <div class=" ...

Customizing the color of text in the fillText() function on an HTML5 <canvas>

I need help changing the color of each line of text in my canvas messages. I've tried creating variables for them, but haven't had any success. Any assistance would be greatly appreciated. function initialize(){ var elem = document.getElemen ...

Struggling to locate desired href links using BeautifulSoup

I'm currently working on compiling a list of hrefs from the Netflix job portal: . Each job posting on this platform comes with an anchor and a specific class: <a class=css-2y5mtm essqqm81>. To ensure accuracy, here is the complete anchor: <a ...

Is there a JavaScript function available to remove comments from previously commented HTML code?

<div id="div1">bar</div> JQuery function addComment(element){ element.wrap(function() { return '<!--' + this.outerHTML + '"-->'; }); } addComment($('#div1')); Looking for assistance in unc ...

The background appears only in the upper portion of the screen upon refreshing the table

Whenever the user clicks on the edit button or when the page is initially loading, a backdrop appears and disappears once the modal is displayed. The backdrop effectively highlights the entire page. However, after updating my table with data via Ajax witho ...

The search bar on the screen does not span the entire width as expected using Bootstrap CSS styling

I have a search form with an input field and a button. When I place the form in a standalone HTML file, the input and button span across the width of the div. However, when I embed it into the specific div I am working on, it shrinks to the left. Here is t ...

Incorporate a background image property using Jquery

Can anyone help me with adding the css background-image:url("xxxxx") property to my code? jQuery('#'+$trackID+' .sc_thumb').attr('src',$thumb_url); jQuery('#'+$trackID+' .sc_container').css('display& ...

Create a smooth scrolling effect for a div with a fixed position

Having trouble scrolling a fixed position div on the page? Are you using this jquery script: $('html, body').animate({ scrollTop: $(".example").offset().top }, 750); I had to set the body overflow property to hidden for another issue. The ...

Place a button to the right side of every row to handle overflow-x

I'm trying to place a button next to each row in my table, but here's the catch: the table is inside a div with a fixed width and overflow-x for responsiveness. I want the button to appear next to each row outside of the container div. Currently ...

How can I apply bold styling to primary nodes in jsTree using CSS?

I am currently utilizing the in conjunction with asp.net mvc. My objective is to apply bold styling to the text using CSS within the main nodes, specifically those with arrows (refer to the image below). https://i.sstatic.net/xg3uF.png Below is the code ...

Is it possible to replace text on click using CSS instead of jQuery?

My new project involves creating a flashcard system. The idea is that when a question is clicked, it reveals the answer and hides the question. To achieve this, I am currently using the following code: jsFiddle <p id="shown">What is stackoverflow?&l ...

The React component is not appearing in Internet Explorer 11

When using a React directive, I invoke it like this: <react-component name="StartAll" props="ctrl.props"> </react-component> Everything works fine in Chrome, Firefox, and Opera, but in IE 11, the React component does not display at all. There ...

Is there a method to increase the vertical length of a ::before pseudo-element within a fixed container?

One issue I'm facing is that the ::before selector doesn't extend vertically in a fixed element. Does anyone know of a way to ensure the background fills the entire height? Currently, when a user scrolls, the ::before elemeent stops once the use ...

Maintain text while transitioning to another page

On my webpage (refer to image for details), users need to select options through a series of steps. The process involves clicking on a link in the top box, then entering a search term in the searchbox to display relevant links in div1. Clicking on a link ...