html - 如何在html表格中设置相同的列?

标签 html html-table

我正在尝试制作相同列大小的表格...但是如果内容超过列大小会自动增加...为什么会这样?

这是我的 html 代码:

    <!DOCTYPE html>
    <html>
    <head>
    <style>
   table {
        background-color: #eaeaea;
        width : 80%;
        border: 1px solid ; 
    }
     td {

        width : 20%;
        border: 1px solid ; 
    }
    </style>
    </head>
    <body>
   <table>
    <tr>
        <td>Alfreds hrtfjfgjkfgAlfreds hrtfjfgjkfgAlfreds hrtfjfgjkfgAlfreds hrtfjfgjkfgAlfreds </td>
        <td>Maria Anders</td>
        <td>Germany</td>
        <td>GermanyGermanyGermanyGermanyGermanyGermany</td>
      </tr>
      <tr>
        <td>Alfreds Futterkiste</td>
        <td>Maria Anders</td>
        <td></td>
        <td></td>
      </tr>
</table>
 </body>
  </html>

这是我的 o/p:

enter image description here

最佳答案

添加 table-layout:fixed 到表格和 word-wrap 到单元格。

像那样:

table {
    background-color: #eaeaea;
    width : 80%;
    border: 1px solid ; 
    table-layout: fixed;
}
 td {

    width : 20%;
    border: 1px solid ; 
    word-wrap: break-word;
}

关于html - 如何在html表格中设置相同的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50879357/

相关文章:

html - Bootstrap 4 具有列宽的响应表

python - 如何遍历整个html表并转换为json数据?

javascript - DIV 和表格 - 多行

c# - 列的值颜色根据条件变化

php - 眼球追踪系统

html - 在 React 应用程序中存储大量数据时我应该更喜欢什么?

html - 首次加载页面时,文本与屏幕左侧对齐

php - 使用 PHP 根据数据库条目突出显示表中的单元格

javascript - 从 <div> 标签中删除表格

javascript - 我的代码 javascript 函数 onchange() 有问题