
我们使用 border-collapse 属性在 HTML 中创建折叠边框。 border-collapse 是一个 CSS 属性,用于设置表格边框应折叠为单个边框或在 HTML 中与其自己的边框分开。

Border-collapse 属性有四个值:separate、collapse、initial、inherit。
如果将折叠作为 border-collapse 属性的值传递,则表格的边框将简单地折叠为单个边框。以下是在 HTML 中创建折叠边框的语法。
立即学习“前端免费学习笔记(深入)”;
border-collapse: collapse;
在下面给出的示例中,我们尝试在 HTML 中创建折叠边框 -
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
table,
tr,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<h2>Tables in HTML</h2>
<table style="width: 100%">
<tr>
<th>First Name </th>
<th>Job role</th>
</tr>
<tr>
<td>Tharun</td>
<td>Content writer</td>
</tr>
<tr>
<td>Akshaj</td>
<td>Content writer</td>
</tr>
</table>
</body>
</html>
以下是上述示例程序的输出。
让我们看另一个例子,将折叠作为 border-collapse 属性的值 -
<!DOCTYPE html>
<html>
<head>
<style>
table {border-collapse: collapse; }
table, td, th { border: 1px solid blue; }
</style>
</head>
<body>
<h1>Technologies</h1>
<table>
<tr>
<th>IDE</th>
<th>Database</th>
</tr>
<tr>
<td>NetBeans IDE</td>
<td>MySQL</td>
</tr>
</table>
</body>
</html>
如果我们通过传递separate作为border-collapse属性的值来创建折叠边框,则各个单元格将被包裹在单独的边框中。
border-collapse:separate;
在下面给出的示例中,我们尝试在 HTML 中创建单独的折叠边框。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
table,tr,th,td {
border:1px solid black;
border-collapse:separate;
}
</style>
</head>
<body>
<h2>Tables in HTML</h2>
<table style="width: 100%">
<tr>
<th >First Name </th>
<th>Job role</th>
</tr>
<tr>
<td >Tharun</td>
<td >Content writer</td>
</tr>
<tr>
<td >Akshaj</td>
<td >Content writer</td>
</tr>
</table>
</body>
</html>
以下是上述示例程序的输出。
让我们看另一个例子,其中将 split 作为 border-collapse 属性的值 -
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: separate;
}
table,
td,
th {
border: 1px solid blue;
}
</style>
</head>
<body>
<h1>Technologies</h1>
<table>
<tr>
<th>IDE</th>
<th>Database</th>
</tr>
<tr>
<td>NetBeans IDE</td>
<td>MySQL</td>
</tr>
</table>
</body>
</html>
如果将 initial 作为 border-collapse 属性的值传递,它将设置为其默认值,即单独的。以下是语法,它使用 HTML 中的 border-collapse 属性的初始属性。
border-collapse:initial;
下面给出一个示例,它使用 HTML 中的 border-collapse 属性的初始属性。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
table,tr,th,td {
border:1px solid black;
border-collapse:initial;
}
</style>
</head>
<body>
<h2>Tables in HTML</h2>
<table style="width: 100%">
<tr>
<th >First Name </th>
<th>Job role</th>
</tr>
<tr>
<td >Tharun</td>
<td >Content writer</td>
</tr>
<tr>
<td >Akshaj</td>
<td >Content writer</td>
</tr>
</table>
</body>
</html>
以上就是如何在HTML中创建一个折叠边框?的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号