我是CSS世界的新手,我正在尝试在锚标记div
伪类弹出窗口中添加一个块级(:hover
)元素。 div元素包含一个表。表格及其像元大小应为动态(允许最小和最大宽度)。我以某种方式设法在IE11中正常工作的以下代码段创建,但文本环绕在chrome中无法正常工作。我曾尝试过自动换行,自动换行,带有Break-word和Break-all选项的分词系统,但是它仅在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>
答案 0 :(得分:2)
@ 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>
答案 1 :(得分:0)
引起问题的规则是this
pre
保留空白序列。仅在源代码中的换行符和<br>
元素处换行。
只需将其删除。
另一个问题是您的“评论”。没有// ...
评论。唯一有效的语法是:/* ... */
(white-space: pre
)
.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>