在HTML表格中自动调整列宽

问题描述 投票:-3回答:1

我正在创建一个包含用户URL历史的表。使用PHP从SQL数据库收集数据,该表根据用户使用下图中的复选框选择的数据生成。

我希望表格使用页面的整个宽度,就像它现在正在做的那样。但是我希望自动调整列宽。正如您在图像中看到的那样,各种列比它们需要的宽得多。

我附上了我在下面使用的CSS代码。

任何帮助将不胜感激。

    table#DisplayData {
    border-spacing: 0;
    width: 100%;
    table-layout:fixed;
    border: 1px solid #ddd;
    word-wrap:break-word
    }

    table#DisplayData th, td {
    text-align: left;
    border: 1px solid #ddd;
    word-wrap:break-word
    margin: auto;
    }

enter image description here

php html css html-table css-tables
1个回答
0
投票

将你的table-layout改为auto(或不包括它,因为auto是默认值)。

演示from MDN

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.