html - 在表格中以固定宽度显示文本

标签 html css

我有一个用户列表,我希望以表格格式显示。我遇到的问题是我只有 30px 的宽度可用,所以我需要将任何超过这个宽度的名称换行。

HTML

<table>
       <tr>
          <td>User ID</td>
          <td style="width:40px;">User's Full Name</td>
       </tr>
       @foreach(var user in @Model)
       {
          <tr>
             <td>@user.Id</td>
             <td style="width:40px;">@user.Name</td>
          </tr>
       }
</table>

CSS

table{
    width:40px;
    background-color: red;
}

任何更长的名称只会迫使宽度增加。

最佳答案

使用这个属性

word-wrap:break-word;

你的 td 标记

<td style="width:40px;word-wrap:break-word;">@user.Name</td>

关于html - 在表格中以固定宽度显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21663844/

相关文章:

jquery - 当另一个 div 在窗口中可见时隐藏元素

css - 一堆 Bootstrap 类或在主 css 中创建自定义 css 类?

javascript - 伪类 :hover persists when Max-Height changes

javascript - 如何单击子元素上的父元素

JavaScript/HTML : How to make a small UI pop out on select

html - 如何将 png 图像转换为内联 svg

css - 从 p :chart barchart 中删除网格和边框

css - 无法在另一个 div 中居中 div

Android:加快(html 格式)文本的显示

html - 如何在 Google map 上方使用 Bootstrap 定位内联文本框和按钮?