由于border-collapse属性,表格的边框半径不起作用

保罗·马克西姆斯

如果我在表格标签上具有border-collapse属性,则不会显示我的边框半径。我需要border-radius属性,如果我删除border-collapse属性,我不会得到我想要的外观,即灰色部分将移到表格的最边缘。

有什么解决方案,其原因是什么?

提前致谢

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

table {
  /*if i comment out the border-collapse property it then shows my radius*/
  border-collapse: collapse;
  margin: 25px 0;
  width: 50%;
  border-radius: 5px;
  font-size: 1.4rem;
  min-width: 400px;
  border: 1px solid #c3c3c3;
  /*margin is just for demo*/
  margin: 20px 20px;
}

table tr {
  border-bottom: solid 1px #d1d1d1;
}

table tr:nth-child(odd) {
  background-color: #eee;
}

table td {
  padding: 10px 15px;
}

table td:first-of-type {
  font-weight: 600;
}
<table>
  <tbody>
    <tr>
      <td>Application</td>
      <td>Natural gas & LPG</td>
    </tr>
    <tr>
      <td>Standards</td>
      <td>BS EN ISO 9001:2008 - EN 331:1998</td>
    </tr>
    <tr>
      <td>Connection</td>
      <td>BSP Taper F</td>
    </tr>
    <tr>
      <td>Finish</td>
      <td>Plated</td>
    </tr>
  </tbody>
</table>

非常

戴尔兰德里

如果您打算在内容背景和边框之间看不到任何间距,则只需删除border-collapse和添加border-spacing: 0border-spacing: 0完全不会影响边框半径,并且还会为您提供边框和内部内容之间没有空格的结果。

在搜索中,似乎同时使用塌陷和半径存在一些异常。也有一些解决方法,您可以在子表上专门使用psuedo标记来获得半径,但是为什么要浪费所有时间,因为您只需要删除边框及其内部内容之间的空间即可border-spacingborder-radius

编辑: 通过使用伪选择器以及border-space: 0您可以实现更明显的边框半径。

我们想要定位与表元素边缘接壤的每个td元素。 table tr td:first-of-typetable tr td:last of type获得左右两侧。然后,我们将每个后续的第一个和最后一个孩子作为目标。最后,如果这是一个动态表,并且您将two在该表中拥有多个数据表,请td:not(:first-child):not(:last-child)在每个类型的第一个和最后一个类型上添加。

I don't get the look I want which is the grey sections to go to the very edge of the table.

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

table {
  /*add border-spacing: 0     instead of     border-collapse: collapse*/
  border-spacing: 0;
  margin: 25px 0;
  width: 50%;
  font-size: 1.4rem;
  min-width: 400px;
  /*margin is just for demo*/
  margin: 20px 20px;
}


/* Start psuedo child tags here, targeting each data elements relevant corners and sides */

table tr td:first-of-type {
   border-left: 1px solid #c3c3c3;
}

table tr td:last-of-type {
   border-right: 1px solid #c3c3c3;
}

/* :not(:first-child):not(:last-child)
This will get any potential data tables that are added 
that are not sides or corners however, they are border 
data tables on top or bottom */    

table tr:first-of-type td:not(:first-child):not(:last-child){
  border-top: 1px solid #c3c3c3;
}


table tr:last-of-type td:not(:first-child):not(:last-child){
  border-bottom: 1px solid #c3c3c3;
}

table tr:first-of-type td:first-child {
    border-top: 1px solid #c3c3c3;
    border-top-left-radius: 5px;
}

table tr:first-of-type td:last-child {
    border-top: 1px solid #c3c3c3;
    border-top-right-radius: 5px;
}

table tr:last-of-type td:last-child {
    border-right: 1px solid #c3c3c3;
    border-bottom: 1px solid #c3c3c3;
    border-bottom-right-radius: 5px;
}

table tr:last-of-type td:first-child {
    border-left: 1px solid #c3c3c3;
    border-bottom:  1px solid #c3c3c3;
    border-bottom-left-radius: 5px;
}

/* End Psuedo tags here */

table tr {
  border-bottom: solid 1px #d1d1d1;
}

table tr:nth-child(odd) {
  background-color: #eee;
}

table td {
  padding: 10px 15px;
}

table td:first-of-type {
  font-weight: 600;
}
<div id="table">
  <table>
    <tbody>
      <tr>
        <td>Application</td>
        <td>here is some data</td>
        <td>Natural gas & LPG</td>
      </tr>
      <tr>
        <td>Standards</td>
        <td>some data in between</td>
        <td>BS EN ISO 9001:2008 - EN 331:1998</td>
      </tr>
      <tr>
        <td>Connection</td>
        <td>some data in between</td>
        <td>BSP Taper F</td>
      </tr>
      <tr>
        <td>more tables</td>
        <td>some data in between</td>
        <td>more data</td>
      </tr>
      <tr>
        <td>some more data still</td>
        <td>some data in between</td>
        <td>and yet more about this data</td>
      </tr>
      <tr>
        <td>Finish</td>
        <td>Plated</td>
        <td>Plated too</td>
      </tr>
    </tbody>
  </table>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章