css - 表格行的顶部和底部边框

标签 css css-tables

<分区>


关闭 4 年前

如何做到这一点?我想在我的表格中的行的顶部和底部边框上使用不同的颜色。如果我使用 display: block,Chrome 会正确显示它,但我不知道这是否是正确的做法。但是,我希望它在 IE8 中工作,但我不知道如何。

我准备了一个可以在 Chrome 中运行的 fiddle :http://jsfiddle.net/s6LQ7/

最佳答案

这适用于 Firefox 和 IE8:

table {
    width: 100%;
    border-collapse: separate; /* Not really necessary unless you use normalize.js */
    border-spacing: 0px; /* take out spaces between cells */
}

tr {
    background-color: #ccc;
}

td {
    width: 50%;
    border-top: 1px solid #f00; 
    border-bottom: 1px solid #0f0; /* move spacing to the cell */
}

以上使用标准的 HTML 显示系统,因此它可以在 IE8 上运行。我有:

  • border-collapse设置为separate,这样可以防止表格折叠边框,因此它会绘制每个边框
  • 添加了 border-spacing 设置为 0px 以删除单元格之间的间距
  • 删除了display指令,允许表格显示为表格
  • border 指令移至单元格,而不是行。

http://jsfiddle.net/s6LQ7/1/

关于css - 表格行的顶部和底部边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14563567/

上一篇:jquery - 隐藏 child parent 而不是 child

下一篇:php - 如何通过 CSS 添加 Logo ?

相关文章:

CSS Chrome 错误?显示水平滚动条 @ 100% 表格单元格

css - Internet Explorer 显示 : table issue

jquery - HTMLDOM : How to change text "files selected" from upload button using jquery or javascript?

html - 在单个 div 中安装 3 个跨度,适用于 Chrome 但不适用于 Firefox

html - 折叠时如何解决两个div之间的空白

html - 如何使用 CSS 在一个 div 中使用多个 span 创建表格

javascript - bxslider 无法在 Bootstrap 3 选项卡中加载

html - 错误 CSS : vertical align in td with input text and image

html - 如何使用 CSS 网格布局在行表上制作悬停状态

html - Sticky <thead> 和 first <tr> 在移动设备和桌面设备上