编辑-原标题:是否有其他方式来实现border-collapse:collapse
的CSS
(为了有倒塌,圆角表)?
事实证明,仅使表格的边框折叠起来并不能解决根本问题,所以我更新了标题以更好地反映讨论内容。
我正在尝试使用该CSS3
border-radius
属性制作带有圆角的表。我正在使用的表格样式如下所示:
table {
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px
}
这是问题所在。我也想设置该border-collapse:collapse
属性,并且设置该属性border-radius
后将不再起作用。有没有一种基于CSS的方式可以获得与border-collapse:collapse
不实际使用相同的效果?
编辑:
我做了一个简单的页面来演示该问题在这里(只火狐/ Safari浏览器)。
看来问题的很大一部分是将表设置为具有圆角不会影响Corner td
元素的角。如果桌子全是一种颜色,那将不是问题,因为我可以td
分别使第一行和最后一行的上角和下角变圆。但是,我在表中使用了不同的背景色来区分标题和条纹,因此内部td
元素也将显示其圆角。
拟议解决方案摘要:
用另一个带有圆角的元素包围桌子是行不通的,因为桌子的四角“渗漏了”。
Specifying border width to 0 doesn't collapse the table.
Bottom td
corners still square after setting cellspacing to zero.
Using JavaScript instead- works by avoiding the problem.
Possible solutions:
The tables are generated in PHP, so I could just apply a different class to each of the outer th/tds and style each corner separately. I'd rather not do this, since it's not very elegant and a bit of a pain to apply to multiple tables, so please keep suggestions coming.
Possible solution 2 is to use JavaScript (jQuery, specifically) to style the corners. This solution also works, but still not quite what I'm looking for (I know I'm picky). I have two reservations:
- this is a very lightweight site, and I'd like to keep JavaScript to the barest minimum
- part of the appeal that using border-radius has for me is graceful degradation and progressive enhancement. By using border-radius for all rounded corners, I hope to have a consistently rounded site in CSS3-capable browsers and a consistently square site in others (I'm looking at you, IE).
I know that trying to do this with CSS3 today may seem needless, but I have my reasons. I would also like to point out that this problem is a result of the w3c specification, not poor CSS3 support, so any solution will still be relevant and useful when CSS3 has more widespread support.
迄今为止最好的解决方案来自您自己的解决方案,它是这样的: