html - 表体列与标题列的宽度不同

标签 html css

你好,我目前正在创建一个表格,第一个标题的文本内容比另一个标题小,而它在主体上的相应列由于它是一个组的名称而具有更宽/更大的内容。我想要实现的是标题和内容上的列应该具有相应的宽度,具体取决于它们中哪个更宽。

这是表格的 fiddle :https://jsfiddle.net/pynechan/b4s3brqc/19/

//HTML
    <h2>Header fixed</h2>
<br/>
<br/>

<table>
    <thead>
        <tr>
            <th>HEADER</th>
            <th>HEADER 2</th>
            <th>HEADER 3</th>
        </tr>
    </thead>

    <tbody>

        <tr>
            <td>1. DATA</td>
            <td>1. DATA 2</td>
            <td>1. DATA 3</td>
        </tr>

    </tbody>
</table>

//CSS


   table {
    max-width:980px;
    table-layout:fixed;
    margin:auto;
}
th, td {
    padding:5px 10px;
    border:1px solid #000;
}
thead, tfoot {
    background:#f9f9f9;
    display:table;
    width:100%;
    width:calc(100% - 18px);
}
tbody {
    height:300px;
    overflow:auto;
    overflow-x:hidden;
    display:block;
    width:100%;
}
tbody tr {
    display:table;
    width:100%;
    table-layout:fixed;
}

tbody{
  scrollbar-face-color: ThreeDFace !important;
  scrollbar-shadow-color: ThreeDDarkShadow !important;
  scrollbar-highlight-color: ThreeDHighlight !important;
  scrollbar-track-color: Scrollbar !important;
  scrollbar-arrow-color: ButtonText !important;
}

最佳答案

只需将此脚本添加到您的 CSS 中即可

th {width:1px;}

关于html - 表体列与标题列的宽度不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50500382/

相关文章:

javascript - 在 fbml iframe 中将正文背景设置为透明

html - 设置选项卡的标签宽度

jquery - 如何在这个 jquery 代码中制作一个用于打开和关闭 div 的按钮?

html - Bootstrap list-inline li 元素交错排列

javascript - 简化 Jquery/Javascript 代码并添加动画

javascript - 如何调整 flex 盒中可折叠元素的比例

HTML & CSS : How to style an HR tag to have a title embedded in it

html - 字体不显示在主机的任何浏览器中

html - 导航元素 float 不受约束

javascript - 为什么这个简单的 JSFiddle 不起作用?