【问题标题】:CSS table cell padding issue in Firefox and IE8Firefox 和 IE8 中的 CSS 表格单元格填充问题
【发布时间】:2010-11-10 22:57:46
【问题描述】:

我在尝试调整表格中的布局时遇到了一些严重问题。在 Firefox 中,我得到奇怪的顶部/底部填充与所有文本不一致。在 Firefox 和 IE8 中,我似乎也无法让我的图标在它们的单元格中垂直居中显示。

如下:

alt text http://www.graphicsdistrict.com/css-issue.png

这是我的表格 css:

table.maxwidth {
    width: 100%;
}

table.standard th {
    color: white;
    font: bold 0.85em Century Gothic;
    padding: 0.6em;
    background-color: #424E4F;
}

table.standard td {
    padding: 0.2em 0.5em;
}

table.standard tr + tr > td {
    border-top: 1px dotted #ccc;
}

table.standard th + th {
    border-left: 1px solid white;
}

table.standard td + td {
    border-left: 1px dotted #ccc;
}

table.standard > tfoot > tr > td {
    border-top: 0.18em solid #424E4F;
    padding: 0.2em 0.5em;
}

table.striped tr.alt td {
    background-color: #eee;
}

table.hover tr:hover td {
    background-color: #e0e0e0;
}

这是我的表格 HTML:

<table class="standard maxwidth striped hover">

    <thead>
        <tr>
            <th class="left">Accessory</th>
            <th class="center">Available</th>
            <th class="right">Options</th>
        </tr>
    </thead>

    <tbody>

        <tr>
            <td class="label"><a href="/mss/Accessory/Edit/4">Mains Charger</a></td>
            <td class="center">

            <img src="/mss/Static/images/icons/tick.png" /></td>
            <td class="right">
            <a href="/mss/Accessory/Archive/4" onclick="if(!confirm('Are you sure you want to archive this Accessory?')) return false;">Archive</a>
            / <a href="/mss/Accessory/Delete/4" onclick="if(!confirm('Are you sure you want to delete this Accessory?\nRelated historical data and reports will be affected!')) return false;">Delete</a>

            </td>
        </tr>

        <tr>
            <td class="label"><a href="/mss/Accessory/Edit/3">Bluetooth Headset</a></td>
            <td class="center">

            <img src="/mss/Static/images/icons/tick.png" /></td>
            <td class="right">
            <a href="/mss/Accessory/Archive/3" onclick="if(!confirm('Are you sure you want to archive this Accessory?')) return false;">Archive</a>

            / <a href="/mss/Accessory/Delete/3" onclick="if(!confirm('Are you sure you want to delete this Accessory?\nRelated historical data and reports will be affected!')) return false;">Delete</a>
            </td>
        </tr>

        <tr>
            <td class="label"><a href="/mss/Accessory/Edit/2">Car Kit</a></td>
            <td class="center">

            <img src="/mss/Static/images/icons/tick.png" /></td>

            <td class="right">
            <a href="/mss/Accessory/Archive/2" onclick="if(!confirm('Are you sure you want to archive this Accessory?')) return false;">Archive</a>
            / <a href="/mss/Accessory/Delete/2" onclick="if(!confirm('Are you sure you want to delete this Accessory?\nRelated historical data and reports will be affected!')) return false;">Delete</a>
            </td>
        </tr>

        <tr>
            <td class="label"><a href="/mss/Accessory/Edit/1">Leather Phone Case</a></td>

            <td class="center">

            <img src="/mss/Static/images/icons/tick.png" /></td>
            <td class="right">
            <a href="/mss/Accessory/Archive/1" onclick="if(!confirm('Are you sure you want to archive this Accessory?')) return false;">Archive</a>
            / <a href="/mss/Accessory/Delete/1" onclick="if(!confirm('Are you sure you want to delete this Accessory?\nRelated historical data and reports will be affected!')) return false;">Delete</a>
            </td>
        </tr>


    </tbody>
    <tfoot>
        <tr>
            <td colspan="3"><a href="/mss/Accessory/New">Add an Accessory</a></td>
        </tr>
    </tfoot>
</table>

请注意,单元格内容之前和/或之后的间距似乎不会对问题产生积极或消极的影响。

编辑

将 CSS 更改为使用 px 单位而不是 em 可修复左栏文本慢动,但不能解决垂直图像居中问题。想法?

编辑 2

现在有问题online here的演示。

【问题讨论】:

  • 你有这个现场样本的链接吗?能够在 firebug 或类似工具中对此进行建模会很有帮助。
  • 好的,完成。我已经上传到graphicsdistrict.com/css-issue/Accessory.htm
  • 哦,很好,发帖人将图像放在自己的服务器上,然后在问题解决后将其删除。有帮助!
  • 其实这是在 StackOverflow 推出自己的图片托管之前,所以我不得不自己把它放在某个地方。不幸的是,当我更改主机时,原始图像丢失了。

标签: html css firefox padding


【解决方案1】:

尝试使用像素作为填充和边框,看看是否能解决问题。我怀疑您使用 ems 会产生一些奇怪的舍入故障,导致 4px/5px 差异。

【讨论】:

  • 谢谢。更改为像素修复了第一列中的文本定位不一致,但并未解决图标列中的垂直居中问题...
  • 很难看出还有什么可能导致问题。如果您可以在某处复制整个页面供我检查,我可能会提供更好的帮助。看起来您有一些应用于表的 css 类(例如“中心”类)在您发布的 css 中没有复制,所以也许您应该看看那些声明的规则是什么?
【解决方案2】:
<td valign="middle"> 

不是最好的方法,因为你不使用 css,但它总是对我有用。

另外,查看单元格的 line-height css 属性。如果您的单元格高 20px,请将 line-height 设置为 20px 等。

【讨论】:

  • 我想你的意思是 valign="middle"? "center" 仅用于水平对齐。
  • 糟糕,你是对的。好久没用了,好像忘记了 ;)
  • 无论如何,它并没有解决问题。无论如何,css 样式的垂直对齐会复制效果。
【解决方案3】:

在你的单元格中试试这个,虽然我认为单元格需要在其中指定高度,但它会起作用。

css vertical-align

【讨论】:

  • 从一开始就存在。
【解决方案4】:

图片在基线上是vertically aligned,为下降者留出了空间 - 以防万一您添加文本。垂直对齐底部,多余的空间消失。

td img {vertical-align:bottom;}

【讨论】:

    猜你喜欢
    • 2012-04-26
    • 2011-06-27
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 2010-12-17
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    相关资源
    最近更新 更多