【问题标题】:How to display a paragraph in a table cell如何在表格单元格中显示段落
【发布时间】:2019-03-28 14:44:50
【问题描述】:

我正在尝试在 td 表格单元格中显示一个小段落 问题是除非 td 单元格是灵活的,否则该段落不会显示 我已经尝试过(空白:pre 和空白:自动换行),但它对我不起作用

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>

<table>
<tr>
 <td style="width: 150px;
             overflow: hidden;
             display: inline-block;
             white-space: word-wrap;"> 
                <div style="width :100px ; white-space: nowrap;">longparagrapgh heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey</div>
                  
         
              </td>
 </tr>
</table>

</body>
</html>

有什么想法吗?

【问题讨论】:

  • “段落不显示”是什么意思?你想让它按照td的宽度换行吗?
  • 你可以试试word-break: break-word;
  • 为什么要隐藏溢出以及为什么要使用 white-space: nowrap;?您的问题不清楚。
  • 是的@Corné 这就是我想说的!对不起,如果我不清楚
  • 谢谢@Harsha,您的解决方案对我有用

标签: html css


【解决方案1】:

使用word-breakword-wrap

<!DOCTYPE html>
<html>

<head>
  <style>
    table,
    th,
    td {
      border: 1px solid black;
    }
  </style>
</head>

<body>

  <table>
    <tr>
      <td style="width: 150px;
             overflow: hidden;
             display: inline-block;
             white-space: word-wrap;">
        <div style="width :100px ; white-space: normal; word-wrap: break-word; word-break: break-word;">longparagrapgh heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey</div>


      </td>
    </tr>
  </table>

</body>

</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    相关资源
    最近更新 更多