【问题标题】:Inconsistent table cell width in different tables不同表格中的表格单元格宽度不一致
【发布时间】:2018-01-14 21:36:16
【问题描述】:

我有三个不同的表格,它们应用了完全相同的样式规则,但奇怪的是,第二列的宽度随着每个后续表格而减小。

规则如下:

#content table {
    font-size: 0.875em;
    border-collapse: collapse;
}

#content th {
    font-size: 1.125em;
    margin-top: 0.5em;
}

#content tr {
    border-bottom: 1px dotted #959da5;
}

#content tr:nth-child(even) {
    background: #dfe5e9;
}

#content tr:last-child {
    border: none;
}

#content td {
    vertical-align: top;
    padding: 1em 0.5em;
}

#content td:first-child {
    width: 33%;
}

#content td:last-child {
    width: 66%;
}

这里是相关页面的链接: http://cisdl.org/gonthier/about-judge-gonthier/judgments.html

发生在 Webkit 和 Firefox 中。这可能是什么原因造成的?

附:发现bug后才加了一个固定的宽度,但是没有用。

【问题讨论】:

    标签: css width css-tables


    【解决方案1】:

    由于某种原因(我猜是边距或填充),您的两个宽度语句相互矛盾。只需删除其中一个就可以了。


    像这样:

    #content td:first-child {
        width: 33%;
    }
    
    #content td:last-child {
    }
    

    【讨论】:

    • 你试过了吗?似乎对我没有多大作用。即使我将宽度设置为绝对像素值,第二个表中的计算宽度也完全关闭。
    • 是的,我在 FF 中尝试过,它在那里工作。澄清我的答案,也许有帮助
    • 谢谢!起初它没有帮助,但后来我做了 tr display: block;它奏效了:)