内容仅在 Chrome 中超出工具提示,在 IE11 中运行良好

Content Goes out of tooltip only in Chrome, works well in IE11

我是 CSS 世界的新手,我正在尝试在锚标记 :hover 伪 class 弹出窗口中添加块级(div)元素. div 元素包含一个 table。 Table 及其单元格大小应该是动态的(可以允许最小和最大宽度)。我以某种方式设法创建了以下在 IE11 中运行良好的代码段,但文本换行在 chrome 中没有按预期工作。我尝试过溢出换行、自动换行、带断字和断字选项的断字,但它只在 IE11 中有效,在 Chrome.

中无效

预期:内容应该被包装,但它在 chrome 中没有按预期工作,但在 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>

导致问题的规则是 white-space: pre

pre
Sequences of white space are preserved. Lines are only broken at newline characters in the source and at <br> elements.

只需删除它。

另一个问题是你的"comments"。没有 // ... 评论。唯一有效的语法是:/* ... */
(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 -> 
  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>

@Saravanan,您的代码片段本身就有问题的答案。我刚刚添加了一个有效的 CSS comment /* */ 语法而不是 // 并在 .value 中注释掉了一些不需要的 CSS 属性,如下所示。而已!!!它将在 IE11 和 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>