The information overflow occurs outside the tooltip specifically in Chrome, while functioning perfectly in IE11

As a newcomer to the CSS world, I am experimenting with adding a block-level element (div) inside an anchor tag's :hover pseudo-class popup. The div element contains a table that needs to have dynamic sizing for both the table itself and its cells (with minimum and maximum width parameters). While I've managed to create a snippet that works correctly in IE11, I'm facing issues with text wrapping in Chrome. I've tried various options like overflow wrap, word-wrap, word break with break-word and break-all settings, but they only seem to work in IE11, not in Chrome.

Expectation: Content should be wrapped correctly in all browsers, but it's currently only working as expected in IE11

.header {
  color: #1aa3ff;
  //width: 30%;
  border: 1px solid #cccccc;
  min-width: 50px;
}

.value {
  //width: 70%;
  border: 1px solid #cccccc;
  padding: 5px;
  min-width: 100px;
  max-width: 250px;
  word-break: break-all;
  overflow-wrap: break-word;
  word-wrap: break-word;
  white-space: pre;
}

a.System {
  position: relative;
  display: inline;
}

a.System .tooltiptext {
  position: absolute;
  width: auto;
  display: inline-block;
  color: red;
  background: #737373;
  border: 2px solid #000000;
  text-align: left;
  visibility: hidden;
  border-radius: 6px;
  z-index: 1;
  //left: 80%;
  margin-left: auto;
  //padding: 5px;
  top: 50%;
  transform: translateY(-50%);
}

a.System .tooltiptext:before {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  margin-top: -12px;
  width: 0;
  height: 0;
  border-right: 12px solid #000000;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
}

a.System .tooltiptext:after {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  margin-top: -8px;
  width: 0;
  height: 0;
  border-right: 8px solid #737373;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

.System:hover .tooltiptext {
  visibility: visible;
}
<h2>Right Tooltip w/ Left Arrow</h2>

<a class="System">Hover over me
  <div class="tooltiptext">
  <table>
    <tr>
      <td class="header">Name</td>
      <td class="value">Sar</td>
    </tr>
    <tr>
      <td class="header">Group</td>
      <td class="value">Group Name1 <br>Group Name 2 Group Name 2 Group Name 2</td>
    </tr>
  </table>
  </div>
</a>

Answer №1

@Saravanan, your code snippet provides a solution to the question at hand. I have made some modifications by replacing // with /* */ for proper CSS commenting and commented out unnecessary CSS properties in the .value section as shown below. This adjustment ensures compatibility with both IE11 and Chrome.


word-break: break-all;
overflow-wrap: break-word;
word-wrap: break-word;
white-space: pre; 

.header {
  color: #1aa3ff;
/*   //width: 30%; */
  border: 1px solid #cccccc;
/*   //min-width: 50px; */
}
a{
  display: block;
}
.value {
/*   //width: 70%; */
  border: 1px solid #cccccc;
  padding: 5px;
  min-width: 100px;
  max-width: 250px;
/*   word-break: break-all;
  overflow-wrap: break-word;
  word-wrap: break-word;
  white-space: pre; */
}

a.System {
  position: relative;
  display: block;
}

a.System .tooltiptext {
  position: absolute;
  width: auto;
  display: inline-block;
  color: red;
  background: #737373;
  border: 2px solid #000000;
  text-align: left;
  visibility: hidden;
  border-radius: 6px;
  z-index: 1;
/*   //left: 80%; */
  margin-left: auto;
/*   //padding: 5px; */
  top: 50%;
  transform: translateY(-50%);
}

a.System .tooltiptext:before {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  margin-top: -12px;
  width: 0;
  height: 0;
  border-right: 12px solid #000000;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
}

a.System .tooltiptext:after {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  margin-top: -8px;
  width: 0;
  height: 0;
  border-right: 8px solid #737373;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

.System:hover .tooltiptext {
  visibility: visible;
}
<h2>Right Tooltip w/ Left Arrow</h2>

<a class="System">Hover over me
  <div class="tooltiptext">
   
  <table>
    <tr>
      <td class="header">Name</td>
      <td class="value">Sar</td>
    </tr>
    <tr>
      <td class="header">Group</td>
      <td class="value">Group Name1 <br />Group Name 2 Group Name 2 Group Name 2</td>
    </tr>
  </table>
  </div>
 </a>

Answer №2

The issue stems from the implementation of white-space: pre

pre
This rule preserves sequences of white space and only breaks lines at newline characters or <br> elements.

To resolve the problem, simply eliminate this rule.

Another concern relates to your usage of "comments". The correct syntax is /* ... */ instead of // ...
(MDN | Comments - CSS)

.header {
  /* width: 30%; */
  color: #1aa3ff;
  border: 1px solid #cccccc;
  min-width: 50px;
}

.value {
  /* width: 70%; */
  border: 1px solid #cccccc;
  padding: 5px;
  min-width: 100px;
  max-width: 250px; /* undefined behavior -> https://stackoverflow.com/questions/8465385/how-can-i-set-the-max-width-of-a-table-cell-using-percentages*/
  word-break: break-all;
  word-wrap: break-word;
}

a.System {
  position: relative;
  display: inline;
}

a.System .tooltiptext {
  position: absolute;
  width: auto;
  display: inline-block;
  color: red;
  background: #737373;
  border: 2px solid #000000;
  text-align: left;
  visibility: hidden;
  border-radius: 6px;
  z-index: 1;
  margin-left: auto;
  top: 50%;
  transform: translateY(-50%);
}

a.System .tooltiptext:before {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  margin-top: -12px;
  width: 0;
  height: 0;
  border-right: 12px solid #000000;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
}

a.System .tooltiptext:after {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  margin-top: -8px;
  width: 0;
  height: 0;
  border-right: 8px solid #737373;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

.System:hover .tooltiptext {
  visibility: visible;
}
<h2>Right Tooltip w/ Left Arrow</h2>

<a class="System">Hover over me
  <div class="tooltiptext">
  <table>
    <tr>
      <td class="header">Name</td>
      <td class="value">Sar</td>
    </tr>
    <tr>
      <td class="header">Group</td>
      <td class="value">Group Name1 <br />Group Name 2 Group Name 2 Group Name 2</td>
    </tr>
  </table>
  </div>
</a>

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

Broken links detected in the Full Page Navigation menu on a one-page website

The hyperlinks on this particular page seem to be malfunctioning despite the fact that the li.a tags are correctly targeting specific section IDs. Markup: <header> <a href="#0" class="nav_icon"><i></i></a> </header> ...

What is causing all three boxes to shift when I'm attempting to move just one of them?

Seeking assistance with a problem I'm encountering. As I work on creating my website, I've run into an issue where trying to move one of the three individual boxes (as shown in the image) causes all three of them to shift together. You can view t ...

What is the best way to create a sliding motion to the right for a menu item, accompanied by a line when it

Is there a way to align the line to the right of the text when it's not selected, and have a new line appear on the left side that pushes the text and removes the line on the right side? Here is the design I'm trying to emulate. If you click t ...

Adjust SVG Checkbox to eliminate any unnecessary padding

I am attempting to customize the MUI5 checkbox CSS fields, and here is the current status: https://i.stack.imgur.com/BROpS.png These are my CSS classes: MuiCheckbox: { styleOverrides: { root: { ".MuiSvgIcon-root": { backgro ...

Employ CSS to target the initial and final items within sets of identical elements

I created the following CSS styles: div { width: 300px; text-align: center; } p:not(.vrt) { text-align: left; } p.vrt { writing-mode: vertical-rl; display: inline-block; } div :nth-child(1 of p.vrt) { margin-left: 0; } div :nth-last-child(1 of ...

Tips on how to change an image tag into a CSS selector

I need to change this tag to a WebElemet using CSS Selector instead of Xpath. I attempted with Xpath as shown below: panelSectionTitle.find( By.cssSelector( "img.aw-layout-right[style='']" ) ) <img style="" class="aw-layout-right" height="2 ...

Position a Bootstrap 3 division within a central division for ultimate centering

I have written a code snippet that looks like this- html, body, .container-table { height: calc(100% - 50px); } /*Centering a div*/ .container-table { display: table; } .vertical-center-row { display: table-cell; vertical-align: middle; } < ...

The mysterious case of the missing CSS file in Node.js

I recently set up a new Node.js Express Project. However, I am facing an issue with the index.ejs file showing the error: Undefined CSS file ('/stylesheets/style.css'). Here is the content of the index.ejs file: <!DOCTYPE html> <html& ...

Tips for overlaying text onto a MaterialUI icon

https://i.stack.imgur.com/cFr5Y.pngI am currently working on a project that requires me to overlay a number on top of an icon. Specifically, I am utilizing the MaterialUI ModeComment icon and attempting to display text over it. Despite trying the following ...

When Css is incorporated within a text, it prevents the use of " " from functioning properly

I am currently developing a GUI application using Qt 4.8. I have a label that displays text in white (the stylesheet has already been set up for this) and I want to change the color of the word "UPDATE" to red. Here is my initial code: //all text in whit ...

Enhancing the appearance of the active menu item with HTML/CSS/JS/PHP

Here's the HTML code I have: <ul class="navigation"> <li><a href="index.php">Home</a></li> <li><a href="index.php?content=about">About us</a></li> </ul> As you can see, the content of the " ...

Is the text in the React chat application too lengthy causing a bug problem?

In my chat application built with React, I am facing an issue where if a user types more than 100 characters, the message gets cut off. How can I fix this problem? Please refer to the image below for reference. {Object.keys(messages).map((keyName) => ...

Grid element's height does not correspond to the responsive square child dimension

In my latest project, I am developing a web application using React and Material-ui. One of the challenges I have encountered is creating a responsive square div for a map component. Unfortunately, attempting to implement a solution from a trick on iamstev ...

What is the best way to allow wider list items to overflow their absolutely positioned container?

My challenge involves a list that is dynamically populated, and I require it to be wider than its absolutely-positioned parent (specifically a custom <select> element implementation). #wrapper { position: relative; border: 1px ...

Anchoring links on a webpage that provide users with a clear indication of their current position within the page

In the scenario of a single-page website with various sections (divs) and a header containing links to different anchors on the page, there is a desire to have an indicator highlight which anchor the user is currently viewing. An example of this can be s ...

Guide to setting the first tab as the default tab using Thymeleaf, Css, and Bootstrap

I am currently working on a project where I need to dynamically create tabs based on a list retrieved from my Spring backend using Thymleaf and Bootstrap. While I have managed to successfully create the tabs and content, I am facing an issue where the fi ...

JavaScript Function Not Executed in Bottom Section

I've implemented AngularJS includes in my project. Below is the code snippet from my index.html: <!DOCTYPE html> <html ng-app=""> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> ...

Is setting the height to 100% a dependable option for container loading during the initial page rendering in CSS?

Upon arrival on the page, I envision the container containing the "search" to expand and occupy the entire screen. Seems simple enough: just set the height to 100%. If the user chooses to scroll down, they will see the rest of the content. It almost fee ...

Adjust and modify class when resizing the window

I've encountered a challenge with my Bootstrap Modal when trying to set the width to 750px on large desktops. When resizing the window to a smaller size, the modal loses its responsiveness. To tackle this, I added a class to the modal to give it a fix ...

Display an image with only a portion visible, no canvas, no frame, and no need

My dilemma involves an img with a surrounding box div. http://jsfiddle.net/6d4yC/7/ 1) I am seeking to display only a portion of the image (250x150) without generating a white overlay when it is in its large size. Placing a #box1 div around the image has ...