在table表格中實現圓角效果


在table中設置border-radius發現不起作用,網上查找了一番,原因是border-collapse:collapse和border-radius不兼容。

設計圖效果

代碼實現效果:

<!DOCTYPE html>
<html>
<head lang="en">
    <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 {/*設置table左邊邊框*/
            border-left: 2px solid #eaeaea;
        }
        table tr th:last-child,table tr td:last-child {/*設置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{/*設置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{/!*設置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 class="table" width="800" cellspacing="0" cellpadding="0">
        <thead class="table_head">
        <tr>
            <th>頭部1</th>
            <th>頭部2</th>
            <th>頭部3</th>
            <th>頭部4</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>1內容1</td>
            <td>1內容2</td>
            <td>1內容3</td>
            <td>1內容4</td>
        </tr>
        <tr>
            <td>2內容1</td>
            <td>2內容2</td>
            <td>2內容3</td>
            <td>2內容4</td>
        </tr>
        <tr>
            <td>3內容1</td>
            <td>3內容2</td>
            <td>3內容3</td>
            <td>3內容4</td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>

 

參考資料地址:http://www.cnblogs.com/purl135/p/4918920.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM