如何在表格单元格中显示段落

时间:2019-03-28 14:44:51

标签: html css

我正在尝试在td表单元格中显示一小段 问题是除非td单元格是灵活的,否则段落不会显示 我已经尝试过(white-space:pre和white-space:word-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: nowrap;">longparagrapgh heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey</div>
                  
         
              </td>
 </tr>
</table>

</body>
</html>

有什么主意吗?

1 个答案:

答案 0 :(得分: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>