html - 固定标题表在调整窗口大小时变形

标签 html css

当水平调整窗口大小时,此固定标题表会变形列。有办法阻止吗?

<!DOCTYPE html>
<html>
<head>
    <style>
        table {
            width: 100%;
            table-layout: fixed;
            border-collapse: collapse;
        }
        table th {
            border-left: 1px solid blue;
        }
        table th,
        table td {
            padding: 5px;
            text-align: left;
            border-left:1px solid blue;
        }

        table th, table td {
            width: 150px;
        }
        table thead tr {
            display: block;
            position: relative;
        }
        table tbody {
            display: block;
            overflow: auto;
            width: 100%;
            height: 300px;
        }
    </style>
</head>
<body>

    <table>
        <thead>
            <tr>
                <th>id</th>
                <th>pick_up_location</th>
                <th>destination</th>
                <th>instruction</th>
                <th>created_at</th>
                <th>status</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>12322</td>
                <td>Whanga Road</td>
                <td>Crescent Street</td>
                <td>Call when arrive</td>
                <td>123442342331</td>
                <td>comming</td>
            </tr>
        </tbody>
    </table>
</body>
</html>

请记住这个固定标题表。意思是当你有 100 行时。您可以滚动该行,但标题位置是固定的。无法删除显示 block 属性。

更新:

使用 Mark answer,表格看起来不错,但在小屏幕上仍然变形。截图

enter image description here

最佳答案

要在调整大小时不出现问题,您必须使用 % 调整高度和宽度。

喜欢:宽度:30%; 高度:40%;

希望对你有帮助。

关于html - 固定标题表在调整窗口大小时变形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38563105/

相关文章:

javascript - 如何使用 Javascript 调整 10 分钟倒计时器中的计时器文本和 "Time is Up"文本

html - 文本对齐不适用于特定长度的 div

html - 两边大小不同的盒子阴影

javascript - 动态更改 following-mouse-div 的颜色,与其下方的颜色互补

css - 如何使用 CSS 变换以正确的视角将两个或多个立方体并排放置?

html - 在 Bootstrap 中移动图像

javascript - 测试 HTML 属性是否存在并获取值

html - 打印 css 样式表 - div 定位

css - 跨浏览器最小高度的最佳和有效方法是什么?

html - 为什么 Pacifico webfont 在 Webkit 浏览器中被裁剪?