css - 我如何通过CSS包装文本

标签 css word-wrap

我正在尝试将长文本包装在表格中,但遇到长文本与其他内容重叠的问题。

示例:

table td {
  white-space: nowrap;
  max-width: 10em;
  overflow: hidden;
  text-overflow:ellipsis;
}

table td:hover {
    overflow: visible;
}
<table>
    <thead>
        <tr>
            <th>Headline 1</th>
            <th>Headline 2</th>
            <th>Headline 3</th>
        </tr>  
    </thead>
    <tbody>
        <tr>
            <td>Bet at home</td>
            <td>10</td>
            <td>80%</td>
        </tr> 
        <tr>
            <td>MOSER 2384 Schermaschine Moser</td>
            <td>20</td>
            <td>40%</td>
        </tr> 
        <tr>
            <td>Bg24 Single 600x120</td>
            <td>30</td>
            <td>50%</td>
        </tr> 
    </tbody>    
</table    

有没有办法通过向内容添加非透明背景来避免这种情况?我该如何处理这个问题?

问候, 凯

最佳答案

只需在鼠标悬停时添加 whitespace:normal

table td {
  white-space: nowrap;
  max-width: 10em;
  overflow: hidden;
  text-overflow:ellipsis;
}

table td:hover {
    overflow: visible;
    white-space: normal;
}
<table>
    <thead>
        <tr>
            <th>Headline 1</th>
            <th>Headline 2</th>
            <th>Headline 3</th>
        </tr>  
    </thead>
    <tbody>
        <tr>
            <td>Bet at home</td>
            <td>10</td>
            <td>80%</td>
        </tr> 
        <tr>
            <td>MOSER 2384 Schermaschine Moser</td>
            <td>20</td>
            <td>40%</td>
        </tr> 
        <tr>
            <td>Bg24 Single 600x120</td>
            <td>30</td>
            <td>50%</td>
        </tr> 
    </tbody>    
</table    

关于css - 我如何通过CSS包装文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29332703/

相关文章:

html - 除最后一个元素外的每个元素的边距

css - PrimeNG 数据表条件单元格格式

html - 浏览器在工具提示库的底部添加了一种边框样式(奇怪的行为)

c# - 如何格式化 C# 字符串以换行以适应特定的列宽?

python - PyCharm 重新格式化代码不会将行换行至指定长度

ios - UILabel 自动换行

css - 居中 v-toolbar-title

javascript - 使用 jQuery 更改菜单选项宽度

c# - 用换行检测 TextBlock 中的换行符数?

html - 无法将表单放入 Bootstrap 中的框中