HTML DOM 样式 borderCollapse 属性
htmlweb developmentfront end technology更新于 2024/5/18 6:36:17
borderCollapse 属性用于设置或返回
| Sr.No | 值 &说明 |
|---|---|
| 1 | separate 这是默认值,每个表格单元格都有单独的边框。 |
| 2 | collapse 指定表格单元格值之间不绘制边框。 |
| 3 | initial 将此属性设置为初始值。 |
| 4 | inherit 继承父级属性值 |
示例
让我们看一个 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>
输出
这将产生以下输出 −

点击"折叠边框"按钮 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

