html - 无法更改 <thead>、<tr> 元素的边框半径

标签 html css

如何改变 thead 和 tr 元素的半径?我希望我的 table 有圆 Angular ,但 border-radius 不适用于 thead 和 tr 但它适用于元素本身。这是 CSS。

table{
    width:100%;
    border-radius:5px;
    background:gray;
}
thead {
    border-radius:5px;
    text-align:left;
    background:blue;
}
tr{
    border-radius:5px;
}
th,td{
    padding:5px;
}

这是 HTML。

   <table>
     <thead>
        <tr>
        <th>No</th>
        <th>Name</th>
        <th>Country</th>
        <th>Age</th>
        </tr>
     </thead>
     <tbody>
        <tr>
        <td>1</td>
        <td>Andy</td>
        <td>UK</td>
        <td>40</td>
        </tr>
      </tbody>
      <tbody> 
    </table> 

最佳答案

这很容易做到。您需要将边框半径添加到行中第一个和最后一个 th 的正确 Angular ,而不是像这样的 thead:

th:nth-child(1) {
    border-radius: 5px 0px 0px 0px;
}

th:nth-last-child(1) {
    border-radius: 0px 5px 0px 0px;
}

这是一个完整的代码片段:

table{
    width:100%;
    border-radius:5px;
    background:gray;
}
tr{
    border-radius:5px;
}
th,td{
    padding:5px;
}
th{
text-align:left;
    background:blue;
    color: #fff;
}
th:nth-child(1) {
    border-radius: 5px 0px 0px 0px;
}

th:nth-last-child(1) {
    border-radius: 0px 5px 0px 0px;
}
   <table>
     <thead>
        <tr>
        <th>No</th>
        <th>Name</th>
        <th>Country</th>
        <th>Age</th>
        </tr>
     </thead>
     <tbody>
        <tr>
        <td>1</td>
        <td>Andy</td>
        <td>UK</td>
        <td>40</td>
        </tr>
      </tbody>
      <tbody> 
    </table> 

关于html - 无法更改 <thead>、<tr> 元素的边框半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57926626/

相关文章:

css - 使 block 元素在文本之间插入自身

html - 我创建了一个供个人使用的简单网站,但其中一个面板移动了

html - 第一个列表项的CSS选择器

html - 通过在文本区域内的任何位置换行来忽略空格和断词

javascript - jQuery中,如何在指定元素后加载ajax内容

javascript - 从 javascript 验证文本框在任何浏览器中都不起作用,但在 IE 中有效

CSS 替代 HTML <center>

javascript - html5/javascript乘以输入类型并显示在表格中

javascript - 重新加载页面后 IE 不保留它的滚动位置

css - 视网膜显示屏上的模糊按钮