What is the best way to ensure that an HTML tooltip is completely visible within a parent container with overflow:hidden?

I need assistance creating a tooltip for my application that displays the full text when hovering over partially hidden writing within a table cell. The goal is to have the tooltip fully visible, unaffected by the overflow:hidden property of the table cell. Below is what I have so far:

CSS:

.tooltip {
    position: relative;
}

.tooltip:hover:after {
    background: rgba(0,0,0,.8);
    color: #fff;
    top: -30px;
    left: 10px;
    border-radius: 15px;
    content: attr(alt);
    padding: 5px 15px;
    position: absolute;
}

HTML:

<table>
    <tr>
        <td style="overflow:hidden">
            <span alt="reallyLongFullWriting" class="tooltip">partiallyHiddenWriting</span>
        </td>
        <td></td>
    </tr>
</table>

Currently, the tooltip gets hidden when it overflows. I am seeking advice on how to ensure the tooltip remains fully visible and does not get cut off. Any suggestions would be greatly appreciated. Thank you.

Edit: Here is an image illustrating the issue:

https://i.sstatic.net/1yW2Y.png

Answer №1

If the structure remains the same, using overflow:hidden will not make the element visible.

To address this issue, one solution is to set a height/width on the td element to create space for the :after element.

table {
  margin: 50px;
}

.tooltip {
  position: relative;
}

td {
  height: 80px;
  overflow: hidden;
  border:1px solid;
}

.tooltip:hover:after {
  background: rgba(0, 0, 0, .8);
  color: #fff;
  top: -30px;
  left: 10px;
  border-radius: 15px;
  content: attr(alt);
  padding: 5px 15px;
  position: absolute;
}
<table>
  <tr>
    <td>
      <span alt="fullWriting" class="tooltip">partiallyHiddenWriting</span>
    </td>
  </tr>
</table>

Another approach is to use fixed positioning BUT maintain the tooltip's relative position by adjusting with negative margins rather than changing top/left/right/bottom properties.

This method may not work if there is scrolling on the page as elements with position: fixed; remain in place relative to the viewport even when scrolled.

table {
  margin: 50px;
}

.tooltip {
  position: relative;
}

td {
  overflow: hidden;
  border:1px solid;
}

.tooltip:hover:after {
  background: rgba(0, 0, 0, .8);
  color: #fff;
  margin-top:-30px;
  border-radius: 15px;
  content: attr(alt);
  padding: 5px 15px;
  position: fixed;
  z-index:999;
}
<table>
  <tr>
    <td>
      <span alt="fullWriting" class="tooltip">partiallyHiddenWriting</span>
    </td>
  </tr>
</table>

A workaround for using fixed positioning on scrollable pages is to apply a transform without effect on a parent element:

body {
 min-height:120vh;
}

table {
  margin: 50px;
  transform:translate(0,0);
}

.tooltip {
  position: relative;
}

td {
  overflow: hidden;
  border:1px solid;
}

.tooltip:hover:after {
  background: rgba(0, 0, 0, .8);
  color: #fff;
  margin-top:-30px;
  border-radius: 15px;
  content: attr(alt);
  padding: 5px 15px;
  position: fixed;
  z-index:999;
}
<table>
  <tr>
    <td>
      <span alt="fullWriting" class="tooltip">partiallyHiddenWriting</span>
    </td>
  </tr>
</table>


Here are some useful links to understand the impact of transform on fixed positioning:

Why does `transform` break `position: fixed`?

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

What is the best way to position an icon to the left of the text?

My code is as follows: <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <span> <i class="fa fa-check"></i> This text is just a test and repeating to ...

Creating an array of items in an HTML template to generate a PDF using Node.js

In my current project, I am utilizing html-pdf for creating PDFs. I have successfully generated all the necessary details in the PDF, however, I am facing an issue with creating a list of items from an array in HTML, which is required for the PDF convers ...

Placing a list item at the beginning of an unordered list in EJS with MongoDB and Node.js using Express

What I've done: I already have knowledge on how to add an LI to UL, but it always goes to the bottom. What I'm trying to achieve: Add an LI to the top so that when my div.todos-wrapper (which has y-oveflow: hidden) hides overflow, the todos you a ...

Adding gaps between hyperlinks in the sidebar navigation using Bootstrap 4

I created a sidebar containing links and I am attempting to add space between each link. Here is the code snippet I have tried: .sidebar-nav>li>a{ padding-bottom: 500px; } Unfortunately, this code is not producing the desired result. Are there any ...

Positioning lines on either side of h1 headings

I have attempted to adjust the positioning of the lines next to the h1 elements on either side and make them scale accordingly when resizing the window. I envision it looking like this: ----This that this Here we go----- I have provided the fiddle li ...

Showcasing images that vary between mobile and desktop views using Bootstrap 4

I have a website where I display 6 columns of images in a row using Bootstrap 4. However, I want to adjust the layout so that when viewed on mobile devices with a smaller screen width, the images are displayed in rows of 4 or 3 columns instead. <link ...

Tips for beginners on determining the best placement for CSS properties on a webpage

As a newcomer to CSS, I have encountered some issues when working with properties in different sections of code. For example: P1: Please review the implementation of #menu and #menu a. The code can be found here. P2: Also, take a look at #menu a specific ...

How can I make a div or iframe stretch to fill the remaining space using javascript, jQuery, or css?

I'm looking for a way to make the middle iframe dynamically fill the remaining space between two fixed height iframes (one at the top and one at the bottom) regardless of the window screen size. Is there a technique or method that can achieve this? th ...

When the window is resized, the div containing a table is getting pushed beyond its original

I have been developing a 'calculadora de creditos' or credits calculator. For this project, I used a responsive layout. Despite searching extensively online for solutions to my issue, I came up empty-handed. CSS CODE: (CSS code here) HTML CO ...

An alternative in the Android platform that simulates the functionality of CompositeOperation in

When working with HTML5/JavaScript, you may come across the compositeoperation property, which allows you to set the mode for placing graphics on a canvas (add/xor/over etc.). Is there an equivalent behavior for manipulating graphics in Android's Can ...

The method for retrieving images for individual posts in Django

I am currently working with two distinct models - one for posts and the other for images. My goal is to display all images associated with each post. The following are the model files I'm using: class Cars_Posts(models.Model): user = models.Forei ...

Concealing information from mobile email apps while showing it on non-media query reading desktops?

I need a reliable method to conceal content from mobile email clients. The ideal solution would hide content by default on devices that don't read media queries, but display on desktop clients that also don't read media queries. Currently, I am ...

Swap the image (either the last or first child) within a div when it is hovered over

I have multiple Div's on my webpage and I am looking to change the color and image when a mouse hovers over them. Changing the text color from grey to blue is quite simple. CSS #div1:hover{color:#0000CC} If I want to change an image, I can achieve ...

Expanding the length of an SVG stroke animation

I've been scouring the depths of the internet in search of a solution for a specific SVG path animation, but my attempts have been fruitless so far. I came across a codepen by Chris Coyier on CSS Tricks that I modified to achieve the desired effect, a ...

Is your max-height transition not functioning properly?

Is there a way to create a collapsible panel using only CSS similar to the Bootstrap bootstrap collapse panel? Why isn't the max-height transition working for me? How can I toggle the panel if it's checked, and have the panel collapse when d ...

Adjust the dimensions of the main svg while keeping the proportions of all elements contained within

Is there a way to adjust the size of the outermost svg while keeping the size of the elements inside the svg unchanged? I've searched online but couldn't find a solution to this specific issue. To provide context and avoid the x-y problem, let ...

Does "br" not play well with flexbox?

After creating a table using flexbox, I made an interesting observation: the br element seems to have no effect within the flexbox. For example: .flexbox { display: flex; flex-wrap: wrap; border: 2px solid red; padding: 2px; } .item { width: ...

What's the best way to make sure an image in CSS respects the height of its parent flexbox section?

This question addresses a clear problem: Flexbox - Img height conflict. However, the accepted answer does not meet my specific needs. One potential solution involves using absolute and relative positioning. While this resolves sizing issues, it interferes ...

Hiding HTML elements with display=none isn't functioning

Here is my code snippet: <?php if($counter==0) { echo "value of counter = $counter" ?> <script type='text/javascript'> document.getElementById("tt").style.display = "none"; </script> <?php } ?> <htm ...

Is there a way to choose the preceding element in Selenium depending on a specific condition?

In my HTML code below: <div class="row"> <div><span class="checkbox"></span></div> <a title="something"></div> </div> <div class="row"> <div><span ...