代码之家  ›  专栏  ›  技术社区  ›  Bhuwan

边框半径和边框在一个表中一起td

  •  6
  • Bhuwan  · 技术社区  · 8 年前

    我想把我的第一次和最后一次 <td> 一 border-radius 所以我的桌子看起来像一张圆形的桌子。

    首先,我将背景应用于 <td> 然后添加 边界半径 ,我认为效果很好(背景从拐角处取整)。

    之后,当我在 <td> ,我看到了一件奇怪的事情(见下面的片段)。

    所以我的问题是为什么边界不是圆形的作为背景?

    堆栈代码段

    table {
      width: 100%;
      border-collapse: collapse;
      table-layout: fixed;
      text-align: center;
      font: 13px Verdana;
    }
    
    table td {
      border: 1px solid #000000;
      padding: 20px;
      background: red;
      color: #ffffff;
    }
    
    table tbody tr:first-child td:first-child {
      border-radius: 20px 0 0 0;
    }
    
    table tbody tr:first-child td:last-child {
      border-radius: 0 20px 0 0;
    }
    <table>
      <tr>
        <td>One</td>
        <td>Two</td>
        <td>Three</td>
      </tr>
    </table>
    5 回复  |  直到 8 年前
        1
  •  9
  •   satyajit rout    8 年前

    尝试 border-collapse: inherit; 并设置“边框间距:0px;”

    table {
      width: 100%;
      border-collapse: inherit;
      table-layout: fixed;
      text-align: center;
      font: 13px Verdana;
      border-radius: 30px;
      border-spacing: 0px;
    }
    
    table td {
      border: 1px solid #000000;
      padding: 20px;
      background: red;
      color: #ffffff;
      border-left: none;
    }
    table td:first-child{
      border-left: 1px solid #000000;
    }
    table tbody tr:first-child td:first-child {
      border-radius: 20px 0 0 0;
    }
    
    table tbody tr:first-child td:last-child {
      border-radius: 0 20px 0 0;
    }
    <table>
      <tr>
        <td>One</td>
        <td>Two</td>
        <td>Three</td>
      </tr>
    </table>
        2
  •  1
  •   Muhammad Awais Iqbal    8 年前

    请在第一行和最后一行四舍五入的情况下签出此解决方案。

    HTML

    <table>
          <tr>
            <td>One</td>
            <td>Two</td>
            <td>Three</td>
          </tr>
          <tr>
            <td>One</td>
            <td>Two</td>
            <td>Three</td>
          </tr>
          <tr>
            <td>One</td>
            <td>Two</td>
            <td>Three</td>
          </tr>
    </table>
    

    CSS

    table {
      width: 100%;
      border-collapse: separate;
      border-radius: 20px;
      table-layout: fixed;
      text-align: center;
      font: 13px Verdana;
    }
    
    table tr {
      border-radius: 20px;
    }
    
    table td {
      border: 1px solid #000000;
      padding: 20px;
      background: red;
      color: #ffffff;
    }
    
    table tr:first-child td:first-child {
      border-radius: 20px 0 0 0;
    }
    
    table tr:first-child td:last-child {
      border-radius: 0 20px 0 0;
    }
    
    table tr:last-child td:first-child {
      border-radius: 0 0 0 20px;
    }
    
    table tr:last-child td:last-child {
      border-radius: 0 0 20px 0;
    }
    

    我希望这对你有帮助。

    小提琴: https://jsfiddle.net/xwqjgb5k/

        3
  •  0
  •   Azeez Kallayi    8 年前

    您可以尝试删除边框折叠:collapse;并添加单元格间距(&A);单元格在表格中填充零。下面的代码可能会帮助您

    table {
      width: 100%;
     
      table-layout: fixed;
      text-align: center;
      font: 13px Verdana;
    }
    
    table td {
      border: 1px solid #000000;
      padding: 20px;
      background: red;
      color: #ffffff;
    }
    
    table tbody tr:first-child td:first-child {
      border-radius: 20px 0 0 0;
    }
    
    table tbody tr:first-child td:last-child {
      border-radius: 0 20px 0 0;
    }
    <table cellpadding="0" cellspacing="0">
      <tr>
        <td>One</td>
        <td>Two</td>
        <td>Three</td>
      </tr>
    </table>
        4
  •  0
  •   YGouddi    8 年前

    只要换一下

    border-collapse: collapse;
    

    并将其设置为

      border-collapse: separate;
    
        5
  •  0
  •   Muhammad Awais Iqbal    8 年前

    请签出更新的解决方案。

    <div class="table-wrapper">
    <table>
      <tr>
        <td>One</td>
        <td>Two</td>
        <td>Three</td>
      </tr>
      <tr>
        <td>One</td>
        <td>Two</td>
        <td>Three</td>
      </tr>
      <tr>
        <td>One</td>
        <td>Two</td>
        <td>Three</td>
      </tr>
    </table>
    </div>
    
    .table-wrapper {
      border-radius: 20px;
      overflow: hidden;
    }
    
    table {
      width: 100%;
      border-collapse: collapse;
      border-radius: 20px;
      table-layout: fixed;
      text-align: center;
      font: 13px Verdana;
    }
    
    table tr {
      border-radius: 20px;
    }
    
    table td {
      border: 1px solid #000000;
      padding: 20px;
      background: red;
      color: #ffffff;
    }
    
    table tr:first-child td:first-child {
      border-radius: 20px 0 0 0;
    }
    
    table tr:first-child td:last-child {
      border-radius: 0 20px 0 0;
    }
    
    table tr:last-child td:first-child {
      border-radius: 0 0 0 20px;
    }
    
    table tr:last-child td:last-child {
      border-radius: 0 0 20px 0;
    }
    

    更新的小提琴: https://jsfiddle.net/xwqjgb5k/1/

    希望对你有帮助。