HTML DOM 样式 borderCollapse 属性

htmlweb developmentfront end technology更新于 2024/5/18 6:36:17

borderCollapse 属性用于设置或返回

元素是否应具有共享边框或独立边框。它可以采用两个值:separate 和 collect。

语法

以下是语法 −

设置 borderCollapse 属性 −

object.style.borderCollapse = "separate|collapse|initial|inherit"

值

属性值解释如下 −

Sr.No值 &说明
1separate
这是默认值,每个表格单元格都有单独的边框。
2collapse
指定表格单元格值之间不绘制边框。
3initial
将此属性设置为初始值。
4inherit
继承父级属性值

示例

让我们看一个 borderCollapse 属性的示例 −

<!DOCTYPE html>
<html>
<head>
<style>
   div {
      display: flex;
      float: left;
   }
   table {
      border: 3px solid black;
   }
   td {
      border: 3px solid lightgreen;
   }
   th {
      border: 3px solid lightblue;
   }
</style>
<script>
   function collapseBorder(){
      document.getElementById("t1").style.borderCollapse="collapse";
      document.getElementById("Sample").innerHTML="The table borders are now collapsed";
   }
</script>
</head>
<body>
<table id="t1">
<tr>
<th>FRUITS</th>
<th>PRICE </th>
</tr>
<tr>
<td>MANGO </td>
<td>40</td>
</tr>
<tr>
<td>APPLE</td>
<td>50</td>
</tr>
</table>
<p>Collapse the above table borders by clicking the below button</p>
<button onclick="collapseBorder()">COLLAPSE BORDER</button>
<p id="Sample"></p>
</body>
</html>

输出

这将产生以下输出 −

点击"折叠边框"按钮 −


相关文章


有用资源