互联网技术 · 2024年2月11日

html如何解决table设置宽度无效的问题

这篇文章主要介绍了html解决table设置宽度无效的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

如果对table设置table-layer:fixed样式后,发现表格中有一行合并过,其它没有合并的行的列宽会平均化,对列宽的设置会失效。

解决方法:

        <col style=”width: 100px;”/>
        <col>
        <col style=”width: 100px;”/>
        <col style=”width: 100px;”/>
        <col style=”width: 100px;”/>

在tbody前面加

.detail {
    padding-bottom: 50px;
    margin-top: 80px;
}

.detail_table {
    table-layout:fixed;/*列宽由表格宽度和列宽度设定。*/
    margin: auto;/*table居中*/
    text-align: center;
    border: 1px solid #804040;
    border-collapse: collapse;
}

.detail_table th {
    padding: 26px;;
}

.detail_table td {
    border: 1px solid #804040;
    padding-top: 16px;
    padding-bottom: 16px;
}

.special {
    text-align: left;
    padding-left: 20px;
}

<div class=”detail”>

    <table class=”detail_table”>

        <thead>
        <th colspan=”5″>选择的选项明细</th>
        </thead>
        <!–写的话就按照你写的宽度,但是如果你写的宽度占不满table它会按照你给的尺寸的比例平分至每个td–>
        <!–现在这么写就是四列是100px,没给数据的那一列占剩下的全部–>
        <col style=”width: 100px;”/>
        <col>
        <col style=”width: 100px;”/>
        <col style=”width: 100px;”/>
        <col style=”width: 100px;”/>

        <tbody>

      &nbsp

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册