How can I make a div overflow outside of a ul container when hovering over it?

Is there a way to make an arbitrary div nested within a ul overflow outside of the ul, even if the ul has a set width of 160px and overflow-y: hidden? The reason for setting it to overflow-y: hidden is because I need the list to be scrollable.

Here is the structure of my list:


  <ul>
      <li> color name</li>
      <div class="tooltip">color name</div>
      <li> color name</li>
      <div class="tooltip">color name</div>
      <li> color name</li>
      <div class="tooltip">color name</div>
    .....
    </ul>

For the names that exceed 160 pixels in width, I would like a hover event to display the full text of the tooltip element and have this text spill outside of the ul.

I have gone through various resources but haven't found a solution yet:

  • Allow specific tag to override overflow:hidden
  • Hovered element to overflow out from an overflow:hidden element css
  • https://css-tricks.com/popping-hidden-overflow/
  • CSS spread <li> horizontally across <ul>
  • Why does inner DIV spills out of outer DIV?
  • What causes a parent container to cut off content in child element?

Answer №1

It appears that your issue can be resolved by utilizing the z-index property on an ::after pseudo-element which displays content upon :hover.

This method creates a hover-triggered "tooltip" that extends beyond the boundaries of its parent div, regardless of the parent's overflow settings. Additionally, this approach ensures that your HTML markup remains valid without any extraneous tags within your lists.


HTML

<ul class="list">
  <li class="list-item">color</li>
</ul>

CSS

.list {
  border: 1px solid black; //visual aid for element boundary
  overflow: hidden;
  width: 160px;
}

.list-item::after {
  content: '';
}

.list-item:hover::after {
  background-color: gray; //for aesthetics only
  content: 'detailed tooltip information regarding the color';
  margin-left: 5px; //for aesthetics only
  position: absolute;
  z-index: 999; //important for layering
}


View a live example on Codepen

Answer №2

To start, it's important to ensure your HTML is properly structured. Only LI elements should be direct children of UL elements. While the incorrect HTML may not cause issues in this specific scenario, it's always best practice to aim for valid HTML to avoid potential unforeseen problems.

If you have set overflow: hidden on the parent UL, then resolving the issue will likely require JavaScript intervention. Many "tooltip" libraries are designed to handle situations like this:

  • When hovering, create a duplicate of the DIV outside of the UL (ideally at the document root or directly under BODY)
  • Position the duplicated DIV so that it overlaps or aligns with the original DIV - JavaScript implementation is needed for this step
  • Remove the duplicate once the user stops hovering over the element.

Most "tooltip" libraries already incorporate these functionalities. Some custom CSS adjustments may be necessary to ensure a tooltip appears on top of an existing element rather than beside it.

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

Interactive HTML5 map featuring geo tagged points

Seeking an HTML5-based tool to efficiently display a zoomable, panable map (similar to Google Maps) and incorporate a circle at a specific location upon clicking a button on a webpage. Any suggestions for HTML5-compatible frameworks or would JQuery be the ...

Positioning a div on the right side of its parent div

Hi there! I'm currently working on a small navbar that has two sections: the left section with an arrow icon and the right section with two icons - an envelope and an exclamation triangle. I've been trying to position the right section in the top ...

Troubleshooting three.js exceeding 2-minute load times and crashing issues

I am currently in the process of developing a 3D game and have encountered an issue with the localhost GET request taking longer than expected. After around 15-45 seconds, the canvas turns white and I receive a warning in the console indicating that the We ...

The next/font feature functions perfectly in all areas except for a single specific component

New Experience with Next.js and Tailwind CSS Exploring the next/font Package Delving into the realm of the new next/font package has been quite interesting. Following the tutorial provided by Next.js made the setup process smooth sailing. I've incorp ...

Complete 2000 forms using a looping mechanism

I am looking to automate the submission of 2000 forms, with a delay of 6 seconds between each submission. This means that all 2000 forms will be submitted after 12000 seconds. Unfortunately, I am unable to use Ajax or cURL for this task. The only function ...

Digital Repeater and Angle Measurer

Seeking Guidance: What is the recommended approach for locating the Virtual Repeaters in Protractor? A Closer Look: The Angular Material design incorporates a Virtual Repeater to enhance rendering performance by dynamically reusing visible rows in the v ...

Maintaining consistent height across all elements in a column while preserving margin: a guide

My query revolves around filling the contents of two columns with different heights within a row. Although the columns themselves are of equal height, the cards inside them are not. +---------------------------+---------------------------+ | +------------- ...

My attempt at creating a straightforward sorting function turned out to be ineffective

My attempt at creating a basic sorting function seems to be failing as it is still returning the original list instead of the sorted one. function sortByPopular (collection) { let items = collection.slice(); items.sort(function(a,b) { re ...

Is it possible to relocate my navigation bar?

I am struggling to align my top horizontal navbar to the right next to the header that reads "Best TV Ever". I have already floated it to the right, but now I need it to move up to the top of the page. Can anyone help me with this? Here is the link to th ...

Can anyone tell me how to retrieve the value of {{org}} in this situation?

<head> <title>My Unique Page</title> </head> <body> <input type="text" ng-model="selectedOrg" ng-show="!isSuperAdmin" readonly /> <select id="nameOrg" ng-model="selectedOrg" ng-cha ...

Tips for incorporating dynamic URLs in Next.js

In my current project using nextjs, I am dealing with fetching images via an API. Right now, I am receiving the "Full image path" (for example, "https://myurl.com/image/imagename.jpg") without any issue. However, I need to figure out how to fetch the image ...

Resetting input field based on callback function

In my simple script, I have two pages - script.php and function.php. The script.php page contains an input field with the ID #code, a link with the ID #submit, and a jQuery function. $('#submit').click(function () { $.ajax({ url: 'f ...

Utilizing jQuery to place an element beside another and maintain its position

I need ElementA to be positioned next to ElementB as shown in this example. The key difference is that I want ElementA to move along with ElementB if the latter is relocated. Is there a way to keep a specific element fixed to another one? Re-calculating ...

retrieve the data attribute of a link within an unordered list

I have been attempting to extract a data attribute from a link within a list when it is clicked on. $(document).on('click', "ul.pagination li a", function(e) { e.preventDefault(); var page = $(this).attr("page"); var article_id = get ...

What is the best way to dynamically update form fields in a database after making a selection in a <select> component?

Currently, I have a form that displays a list of stars (stellar objects) with a <select> control and two <inputs>. I am seeking guidance on how to populate the two inputs from the database when the user changes the selection in the <select&g ...

"Implementing a full page refresh when interacting with a map using

Here is an example of how I display a map on the entire page: <div id="map_canvas"> </div> UPDATE 2: I have successfully displayed a menu on the map, but there is a problem. When I click on the button, the menu appears briefly and then disapp ...

Error arises on Github when submitting a pull request due to a conflicted package

When facing conflicts in the package.json file while submitting a pull request, what is the best approach to resolve them? I usually attempt using git pull origin, but it tends to generate numerous merge commits. ...

Looking to locate .zip files using PHP Simple HTML DOM Parser?

Just started using PHP Simple HTML DOM Parser and I'm attempting to display links that have either a .zip or -animal.jpg at the end, but I seem to be stuck. I've done some searching online, but unfortunately, all I see below is a blank screen. ...

Verify if session is in existence

Currently in the process of setting up my NodeJS and Express App, utilizing Passport for authentication through Google Sign In and Login. All functionalities work flawlessly when tested on localhost. The sign-in process is smooth, and upon checking, I can ...

Access the Fetch API endpoint located within the /app directory in the Next JS version 13

Currently, I am in the process of developing an API and fetching data within Next JS 13. I recently came across this query: How do you put api routes in the new app folder of Next.js? After researching, I have come up with the following scripts: /src/app ...