css設(shè)置table圓角邊框不起作用的原因是:屬性border-collapse:collapse和屬性border-radius不兼容。正確方法如【border-collapse: separate;border-spacing:0】。
本文環(huán)境:windows10、css3,本文適用于所有品牌的電腦。
原因分析:
在table中設(shè)置border-radius發(fā)現(xiàn)不起作用,原因是border-collapse:collapse和border-radius不兼容。
(學(xué)習(xí)視頻分享:css視頻教程)
css:
border-collapse: separate; border-spacing: 0;
代碼實(shí)現(xiàn):
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> #table_wrap > table { font-size: 16px; text-align: center; margin: 0 auto; border-collapse: separate; border-spacing: 0; border: 2px #000; } table thead tr,table tbody tr { height: 50px; line-height: 50px; /*background-color: pink;*/ } table tr th:first-child,table tr td:first-child {/*設(shè)置table左邊邊框*/ border-left: 2px solid #eaeaea; } table tr th:last-child,table tr td:last-child {/*設(shè)置table右邊邊框*/ border-right: 2px solid #eaeaea; } table tr td:first-child, table tr td:nth-child(2), table tr td:nth-child(3), table tr td:last-child{/*設(shè)置table表格每列底部邊框*/ border-bottom: 2px solid #eaeaea; } /*table tr:last-child td:first-child, table tr:last-child td:nth-child(2), table tr:last-child td:nth-child(3), table tr:last-child td:last-child{/!*設(shè)置table表格最后一列底部邊框*!/ border-bottom: 2px solid #000; }*/ table tr th { background: #eaeaea; } table tr:first-child th:first-child { border-top-left-radius: 12px; } table tr:first-child th:last-child { border-top-right-radius: 12px; } table tr:last-child td:first-child { border-bottom-left-radius: 12px; } table tr:last-child td:last-child { border-bottom-right-radius: 12px; } </style> </head> <body> <div id="table_wrap"> <table width="800" cellspacing="0" cellpadding="0"> <thead> <tr> <th>頭部1</th> <th>頭部2</th> <th>頭部3</th> <th>頭部4</th> </tr> </thead> <tbody> <tr> <td>1內(nèi)容1</td> <td>1內(nèi)容2</td> <td>1內(nèi)容3</td> <td>1內(nèi)容4</td> </tr> <tr> <td>2內(nèi)容1</td> <td>2內(nèi)容2</td> <td>2內(nèi)容3</td> <td>2內(nèi)容4</td> </tr> <tr> <td>3內(nèi)容1</td> <td>3內(nèi)容2</td> <td>3內(nèi)容3</td> <td>3內(nèi)容4</td> </tr> </tbody> </table> </div> </body> </html>
實(shí)現(xiàn)效果: