【发布时间】:2013-05-19 21:49:40
【问题描述】:
我目前在表格上实现圆形边框,如下所示:
.tbor {
border-width:3px;
border-style:solid;
border-color:lighten(@col-border,10%) darken(@col-border,10%) darken(@col-border,10%) lighten(@col-border,10%);
border-radius:12px;
}
.tbor>tr>td, .tbor>thead>tr>td, .tbor>tbody>tr>td, .tbor>tfoot>tr>td, .tbor>tr>th, .tbor>thead>tr>th, .tbor>tbody>tr>th, .tbor>tfoot>tr>th {
border: 1px solid @col-border;
padding: 2px;
}
.tbor_tl {border-top-left-radius: 8px;}
.tbor_tr {border-top-right-radius: 8px;}
.tbor_br {border-bottom-right-radius: 8px;}
.tbor_bl {border-bottom-left-radius: 8px;}
这很好用,但它需要我在左上角、右上角、左下角和右下角的单元格上手动设置类。
在另一个项目中,我对单元格使用了以下规则:
.tbor>thead>tr:first-of-type>td:first-of-type,.tbor>colgroup+tbody>tr:first-of-type>td:first-of-type,.tbor>tbody:first-child>tr:first-of-type>td:first-of-type,.tbor>tr:first-of-type>td:first-of-type{border-top-left-radius:8px}
.tbor>thead>tr:first-of-type>td:last-of-type,.tbor>colgroup+tbody>tr:first-of-type>td:last-of-type,.tbor>tbody:first-child>tr:first-of-type>td:last-of-type,.tbor>tr:first-of-type>td:last-of-type{border-top-right-radius:8px}
.tbor>tbody:last-child>tr:last-of-type>td:first-of-type,.tbor>tfoot>tr:last-of-type>td:first-of-type,.tbor>tr:last-of-type>td:first-of-type{border-bottom-left-radius:8px}
.tbor>tbody:last-child>tr:last-of-type>td:last-of-type,.tbor>tfoot>tr:last-of-type>td:last-of-type,.tbor>tr:last-of-type>td:last-of-type{border-bottom-right-radius:8px}
这是一个丑陋的混乱,它完全依赖于所有表格单元格是 1x1。当任何单元格(尤其是底部的单元格)具有colspan 或rowspan 时,它会完全崩溃。
有没有办法做到这一点? JavaScript 没问题:可以假设所有表都是静态的,或者动态表具有静态的第一行和最后一行。
【问题讨论】:
-
我是菜鸟,但为什么不
border-radius:1px 1px 1px 1px而不是说,左上角,右下角,左下角......? -
因为我一次只设置一个角?
-
这些表很大吗?超过几千行的表格加载缓慢,您是否考虑过使用跨度而不是表格单元格?你能提供一个我们可以玩弄的最坏情况吗?
-
@TravisJ 我看不出一千个跨度比一千个表格单元格好多少。无论如何,最大的表格大约有 5x100 个单元格大小。
-
@TravisJ Here's 期望结果的示例。
标签: css css-tables