关于table表格中圆角不生效的问题
某天我写了一个表格长这样:
问题来了我设置了四个角的圆角,但是最后没生效!并且th和td错开了一像素看起来非常不舒服。
代码如下:
.computedtable th:first-child {
border-top-left-radius: 12px;
}
.computedtable th:last-child {
border-top-right-radius: 12px;
}
.computedtable tr:last-child td:first-child {
border-bottom-left-radius:12px;
}
.computedtable tr:last-child td:last-child {
border-bottom-right-radius: 12px;
}
查询原因之后发现是给表格设置的这个属性导致: border-collapse:collapse;
划重点划重点划重点!!!!!!!!!!
border-collapse:collapse和border-radius不兼容!!!!!!!!!!!
不兼容!! 不兼容!! 不兼容!! 不兼容!!
既然不能合并,于是修改属性: border-collapse:separate;
设置之后还有一点美观上的问题,表头和表身错开,比如border重合了:
解决方法:给td、按照所处位置设置border,eg:
.computedtable th:nth-child(-n+4){
border-left: 1px solid white;
}
.computedtable tr th:nth-child(1){
border-left:1px solid #ffaa00 ;
}
.computedtable tr td{
border-bottom: 1px solid #ffaa00 ;
border-left: 1px solid #ffaa00 ;
}
.computedtable tr td:last-child,.computedtable tr th:last-child{
border-right: 1px solid #ffaa00;
}
对齐了!!!治好了我的强迫症!一个漂漂亮亮的表格就做好啦~都是小细节上的功夫