css怎么让表格四角变圆角?下面本篇文章给大家介绍一下使用CSS属性设置table表格圆角的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
使用CSS属性设置table表格圆角
有些情况下需要给表格设置圆角,但是border-radius与border-collapse:collapse;会产生冲突,给table设置border-radius并不会生效。
可以通过减少单元格框线的方式来不设置boder-collapse;collapse; 这样就能给表格添加圆角了。
源码如下:
*{margin: 0;padding: 0;}
table{
margin: 50px auto;
border-spacing: 0;
}
table th{
width: 100px;
height: 30px;
line-height: 30px;
background: gray;
color: white;
}
table td{
width: 100px;
height: 30px;
text-align:center;
line-height: 30px;
}
table tr th:first-child,
table tr td:first-child{
border-left: 1px solid gray; /* 给table设置左边框 */
}
table tr th:last-child,
table tr td:last-child{
border-right: 1px solid gray; /* 给table设置右边框 */
}
table tr td:first-child,
table tr td:nth-child(2),
table tr td:nth-child(3){
border-bottom: 1px solid gray; /* 给tbody各列设置下边框 */
}
table tr:first-child th:first-child{
border-top-left-radius: 10px; /* 设置table左上圆角 */
}
table tr:first-child th:last-child{
border-top-right-radius: 10px; /* 设置table右上圆角 */
}
table tr:last-child td:first-child{
border-bottom-left-radius: 10px; /* 设置table左下圆角 */
}
table tr:last-child td:last-child{
border-bottom-right-radius: 10px;/* 设置table右下圆角 */
}
1-11-21-3
2-12-22-33-13-23-34-14-24-3
效果图如下:
更多web前端知识,请查阅 HTML中文网 !!