【问题标题】:Whenever I collapse the table border in html I cant edit border color每当我在 html 中折叠表格边框时,我都无法编辑边框颜色
【发布时间】:2022-12-16 13:02:29
【问题描述】:

您好,我正在编写一些 html 代码,其中我也必须制作表格以进行对比。在一个表格中,我将 border-collapse 属性设置为单独的,而在另一个表格中,我已将其折叠。问题出在另一个表中,因为由于某种原因我无法使用 color 属性更改边框颜色,因此我覆盖它以折叠边框。这是一些代码供审查

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Living vs Non living</title>
  <style type="text/css">
    body{background-color:RGB(255,251,214)}
    table,th,td{border:1px solid red}
    table{border-collapse:separate;border-spacing:20px}
  </style>
</head>
<body>
<table>
    <caption><h3>Livings things and non-living things</h3></caption>
    <tr>
        <th style = background-color:red;color:white>Living things</th>
        <th style = background-color:red;color:white>Non Living things</th>
    </tr>
    <tr>
        <td>Consists of cell</td>
        <td>No cell</td>
    </tr>
    <tr>
        <td>Needs food for energy</td>
        <td>Needs no food</td>
    </tr>
    <tr>
        <td>Shows growth and movement</td>
        <td>No growth and movement</td>
    </tr>
</table>
<table style="border-width:1px;border-style:solid;border-color:blue;color:white">
    <caption><h3>Livings things and non-living things</h3></caption>
    <tr>
        <th style = background-color:cyan>Living things</th>
        <th style = background-color:cyan>Non Living things</th>
    </tr>
    <tr>
        <td>Consists of cell</td>
        <td>No cell</td>
    </tr>
    <tr>
        <td>Needs food for energy</td>
        <td>Needs no food</td>
    </tr>
    <tr>
        <td>Shows growth and movement</td>
        <td>No growth and movement</td>
    </tr>
</table>
</body>
</html>

感谢您花时间阅读我的问题

【问题讨论】:

  • 抱歉贴错了第二个表格样式的代码是:<table style="border-width:1px;border-style:solid;border-color:blue;border-collapse:collapse">

标签: html css


【解决方案1】:

事实证明它起作用了我需要做的就是单独编辑 td 和 th 以及在上面的标题中完成的。我认为这是为了让编辑表格中的所有元素变得更容易

【讨论】:

    【解决方案2】:

    当使用值为collapseborder-collapse属性时,表格的边框颜色将由table元素的border-color属性决定,而不是由单个@987654326的border-color属性决定@ 和 th 元素。您仍然可以为单个单元格设置边框颜色,但它会被表格的边框颜色覆盖。

    以下是使用 border-collapse: collapse 属性时如何设置表格边框颜色的示例:

    table {
        border-collapse: collapse;
        border-color: blue;
    }
    
    td {
        border-color: red; // This will not have any effect when using border-collapse: collapse
    }
    

    您还可以使用 border 速记属性在单个声明中设置边框颜色、样式和宽度。

    table {
        border-collapse: collapse;
        border: 1px solid blue;
    }
    
    td {
        border: 1px solid red; // This will not have any effect when using border-collapse: collapse
    }
    

    【讨论】:

      猜你喜欢
      • 2011-12-18
      • 2011-05-05
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      • 2015-08-19
      • 1970-01-01
      • 2015-09-28
      相关资源
      最近更新 更多