The nested division remains confined within its parent container without extending into other sibling elements

My table layout is quite complex, and I need to implement a hover menu that appears with its position adjusted based on each row's position. Each row in the table is generated dynamically using React props.map function, which gives me the flexibility to manipulate the z-index of rows. However, I'm facing an issue where the menu does not appear on top of the "th" element as intended.

I suspect this issue has something to do with the Stacking Context, but I am unsure how to resolve it.

You can view a simplified version of my table in this fiddle: https://jsfiddle.net/4n9bj16x/2/

I have tried various solutions, some of which worked partially but caused other problems. What I ultimately need is to keep the first column fixed while ensuring that the menu overlaps all sibling "th" elements.

Approaches that partially worked but broke something else:

  • Removing the "sticky" position from the "th" results in perfect overlapping of the menu but breaks the fixed first column functionality.
  • Setting the menu to be relative positioned adds it to the normal document flow, but causes unwanted growth effects.
  • Eliminating the background-color property of "th" makes it invisible and reveals underlying columns during scrolling.

Any assistance would be greatly appreciated!

Note: The original table is coded in React and SCSS for reference purposes.

HTML & CSS code example (scss format for readability):

.overflowTable {
 overflow-x: scroll;
 margin-left: 0;
 overflow-y: visible;
 padding: 0;
 position: relative;
 height: 100vh;
}
... (CSS styles continue)
 
<div class="overflowTable">
  <table>
    ... (HTML table structure continues)
  </table>
</div>

Answer №1

ANSWER:

In order to fix the issue, you need to remove background-color: inherit; from the th element.

For more information on the inherit keyword in CSS, you can refer to the w3schools resource.

The inherit keyword specifies that a property should inherit its value from its parent element.

UPDATE:

I apologize for the confusion earlier.

You have assigned a z-index: 2; to all elements with the .content class, meaning they all have the same index. To resolve this, add z-index: 3; to the second row instead. You will notice the difference then. :)

You can view the code snippet here.

<th class="content" style="z-index: 3!important;">

Apologies for any language errors.

Answer №2

Changing z-index of tr's and th's on hover

.overflowTable {
 overflow-x: scroll;
 margin-left: 0;
 overflow-y: visible;
 padding: 0;
 position: relative;
 height: 100vh;
}
 table {
 border-collapse: separate;
}
  tr {
 background-color: white;
 position: relative;
 z-index: 1;
}
tr:hover {
  z-index: 2; 
   }
   tr:hover th {
  z-index: 3;
}

 th {
 border-right: 2px solid #eee;
 font-weight: 600;
 color: #333;
 left: 0;
 position: sticky;
 z-index: 2;
 background-color: inherit;
}
 tbody tr:hover {
 background-color: #fafafa;
}
 tbody th {
 cursor: pointer;
}
 tbody td {
 cursor: grab;
}
 tbody td:active {
 cursor: grabbing;
}
 .headerTable {
 font-family: "Open-sans", sans-serif;
 font-style: normal;
 font-weight: 600;
 font-size: 18px;
 line-height: 25px;
 color: #666;
 border-bottom: 2px solid #eee;
 padding: 10px 30px;
 min-width: 150px;
}

 .content {
 padding: 10px 30px;
}
 .content .actualMenu {
 visibility: hidden;
}
 .content .menuMore {
 position: absolute;
 width: 250px;
 visibility: hidden;
 right: 0;
 background-color: #333;
 color: white;
 box-shadow: 0 4px 2px rgba(0, 0, 0, 0.1), 4px 4px 10px rgba(0, 0, 0, 0.1);
}
 .content:hover .actualMenu, .content:hover .menuMore {
 visibility: visible;
}
 .content .title {
 display: flex;
 flex-direction: row;
 align-items: center;
 justify-content: center;
}
 .content .title .name {
 flex: 1;
}
 .content .title .moreOptions {
 position: relative;
 flex: 0;
}
 
<div class="overflowTable">
  <table>
    <thead>
      <tr>
        <th class="headerTable">
          Name
        </th>
        <td class="headerTable">
          Status
        </td>
        <td class="headerTable">
           People
        </td>
        <td class="headerTable">
           Date
        </td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th class="content">
        <div class="title">
          <div class="name">
            Name
          </div>
          <div class="moreOptions">
            <span class="actualMenu">...</span>
            <div class="menuMore">              Options<br/>
              Options<br/>
              Options<br/>
              Options<br/>
              Options<br/>
            </div>
          </div>
        </div>
        </th>
        <td class="content">
          Status
        </td>
        <td class="content">
          First Person
        </td>
        <td class="content">
          Random Date
        </td>
      </tr><tr>
        <th class="content">
        <div class="title">
          <div class="name">
            Name
          </div>
          <div class="moreOptions">
            <span class="actualMenu">...</span>
            <div class="menuMore">                   Options<br/>
              Options<br/>
              Options<br/>
              Options<br/>
            </div>
          </div>
        </div>
        </th>
        <td class="content">
          Status
        </td>
        <td class="content">
          First Person
        </td>
        <td class="content">
          Random Date
        </td>
      </tr>
    </tbody>
  </table>
</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

Nothing is being returned when using JQuery AJAX POST

Having trouble identifying the issue, as all that seems to happen is the URL changes to "http://localhost/?search=test" when entering "test", for example. index.php <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquer ...

Personalized KeyCloak registration link

I need to add a custom request parameter to the registration URL of Keycloak and then extract it into a form. My Approach: Using the Keycloack.js adapter, I successfully generated a custom registration URL in my React project like this: const baseRe ...

Unable to enable auto-scroll feature in DIV element

My div has an auto-scroll feature that works fine, but I've encountered an issue when using multiple smileys in a single chat post. The auto scroll seems to stop working correctly and only scrolls 2 lines from the bottom. I attempted to fix this with ...

Is there a way to automatically disable other options in a MUI Select once one option has been selected?

Can the options in the select menu be dynamically changed based on the value selected in another menu? For example: if option A is selected show options C and D in the other menu but if option B is selected show options E and F Here is a visual represent ...

Incomplete JSON response being received

We set up an express server to call an API and successfully requested the JSON object in our server. However, we are facing an issue where the JSON data is getting cut off when being displayed as a complete object on the client side. We tried using parse i ...

Displaying variables in JavaScript HTML

<script type ="text/javascript"> var current = 0; </script> <h3 style={{marginTop: '10', textAlign: 'center'}}><b>Current Status: <script type="text/javascript">document.write(cur ...

Utilizing Javascript to collapse the initial DIV element discovered with a specific classname

Seeking assistance with this particular Javascript code. The objective is to collapse the next element. Unfortunately, it is not functioning as expected due to an error in closing the first DIV in each block. The script should aim to collapse the initial ...

The Google Chart is failing to show up on the screen

I'm having trouble implementing a feature that involves selecting a region from a dropdown list and requesting rainfall data to display in a Google Chart. Unfortunately, I've encountered some issues with it. Could you please help me identify ...

unable to connect css file to document

My index.html file is not reading the style.css file for some reason, even though it is linked. I have added the type and checked the path, but still facing issues. Can anyone help troubleshoot this problem? Thank you. https://i.sstatic.net/xxpBV.png htt ...

Ways to prevent scrolling or switching to the next tab when my javascript function yields a false result

//HTML Code <div id="navigation1"> <ul> <li><a href="#"><input type="submit" value="Next" onClick="return checkfhname()" /></a></li> </ul> </div> Whenever my Javascript function checkfhname() r ...

Toggle the visibility of a Div element using PHP and jQuery

I am attempting to create 3 buttons that, when clicked, display the content of a PHP file. Here is what I have done so far: In the main HTML file: <div class="buttons"> <a class="showSingle" target="1">Logg</a> <a class="showSingle ...

Updating image URL for grouped objects with Fabric JS

Check out this link :http://jsfiddle.net/mishragaurav31/ang58fcL/#base I created two groups of objects; one consisting of a circle and text, and the other with two images. When I try to change attributes for group 1, it works fine. However, when attempt ...

When the URL is modified, triggering an event to load

Is there a way to make a page load directly to a specific section and automatically open an accordion? For instance, I have a page with multiple accordions displayed vertically. I already know that using id's in the URL like page#accordion1 will scro ...

Creating a basic React application without internet accessWould you like to learn how to

Residing in Kyiv, Ukraine, I often face power outages due to the ongoing terrorist acts by Russia. Despite this challenge, I am eager to learn React. However, I find myself in a dilemma - how can I create, view, and deploy a simple React app without a stab ...

What could be causing these "areas" or "panels" to intersect with each other?

As I work on constructing a website, I'm facing an issue with the top two sections. They appear correctly when my screen is full size, but as soon as I adjust the screen size, they jump down and create white space. It seems like I may have approached ...

Having trouble integrating CanvasJS into a NextJS application

I have integrated CanvasJS into my NextJS app by placing the files canvasjs.react.js and canvasjs.min.js in the pages folder. I then imported them within a page like so: import React from 'react' import CanvasJSReact from './canvasjs.react& ...

Using Formik's FieldArray to handle nested form inputs

I am facing some challenges with Formik FieldArray integration in my React Web app. Specifically, I am unable to retrieve the values of input fields when I enter a value in the text field. It seems like the handleChange event is not working as expected. Ho ...

Folding into itself lies another folding

While attempting to nest a collapse area inside another collapse, I encountered an issue. Upon clicking to open the first collapse, it functions perfectly. However, when trying to open the second collapse (nested within the first one), it inadvertently cl ...

Preparing Your React Application: The current configuration does not support the experimental 'jsx' syntax

I am currently in the process of packaging app "x" and incorporating it into another app "y". Here is my configuration: x/package.json: { "name": "x", "version": "0.0.1", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.17.0 ...

Tips for navigating back to the previous component in React:

Greetings! I'm currently working on a simple CRUD example using React.Js and TypeScript. In my project, I have set up the following component hierarchy: -FetchNaselje --Modal ---AddNaselje It's structured such that AddNaselje is a child of Moda ...