EDIT:
Rereading the question I understood that you want the effect only on the table line <tr>
. Then follow two ways of doing following the idea of the answer already given.
tr {
position: relative;
border: 1px solid salmon;
}
tr:first-of-type:hover::after {
content: attr(data-text);
position: absolute;
z-index: 99;
background-color: powderblue;
border-radius: 5px;
padding: 4px 10px;
font-size: 10px;
font-family: sans-serif;
}
td {
border: 1px solid salmon
}
<table>
<tr data-text="descrição n# 1">
<td >TR</td>
<td>com hover::after</td>
</tr>
<tr title="descrição n# 2">
<td>TR</td>
<td>com title=""</td>
</tr>
</table>
Follows a simple solution using pseudo-element and a custom attribute in content
td {
position: relative;
border: 1px solid salmon;
}
td:hover::after {
content: attr(data-text);
position: absolute;
z-index: 99;
top: 115%;
left: 0;
background-color: powderblue;
border-radius: 5px;
padding: 4px 10px;
font-size: 10px;
font-family: sans-serif;
}
<table>
<tr>
<td data-text="descrição n# 1">item 1</td>
<td data-text="descrição n# 2">item 2</td>
</tr>
<tr>
<td data-text="descrição n# 3">item 3</td>
<td data-text="descrição n# 4">item 4</td>
</tr>
</table>
Now, there are some elements that accept the attribute title=""
on the tag, and they work similarly to <abbr>
such as the tag <a>
and the <p>
<a href="#" title="meu link">deixe o mouse</a>
<p title="tag p">isso é um P</p>
You can do the same on the table, but you won’t be able to make it work on TR only on TD
table {border: 1px solid black}
<table>
<tr title="teste TR 1">
<td title="teste 1" data-text="descrição n# 1">item 1</td>
<td title="teste 2" data-text="descrição n# 2">item 2</td>
</tr>
<tr title="teste TR 1">
<td title="teste 3" data-text="descrição n# 3">item 3</td>
<td title="teste 4" data-text="descrição n# 4">item 4</td>
</tr>
</table>
OBS: Accessibility and attribute considerations title
The use of the title attribute is highly problematic for:
- People who use touch-only devices
- People navigating with keyboards
- People navigating with the aid of assistive technology, such as screen readers or magnifying glasses
- People with disabilities in motor control
- People with cognitive concerns
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title
William, but already adding the comment/ legend, why you need something similar to what you are doing ?
– David
because my tables are not with text, spaces and
<br>
s– Costamilam