使用Bootstrap 5的表格类和嵌套表格类。这些类可以帮助设置表格的外观和样式。以下是一个完整的HTML示例代码,其中包含一个带边框的嵌套表格:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bootstrap Table Example</title>
<!--引入Bootstrap CSS-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>Example Table</h1>
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>john@example.com</td>
<td>555-1234</td>
</tr>
<tr>
<td colspan="4">
<table class="table table-bordered table-sm">
<thead>
<tr>
<th>ID</th>
<th>Product Name</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Product A</td>
<td>$10</td>
<td>5</td>
</tr>
<tr>
<td>2</td>
<td>Product B</td>
<td>$20</td>
<td>3</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>3</td>
<td>Bob</td>
<td>bob@example.com</td>
<td>555-5555</td>
</tr>
</tbody>
</table>
</div>
<!--引入Bootstrap JavaScript-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
在上面的代码中,我们首先引入Bootstrap 5的CSS和JavaScript文件。然后我们创建了一个包含一个表格的容器。表格的类设置为“table table-bordered”。
在表格的thead部分,我们定义了表格的列标题。在表格的tbody部分,我们添加了三个数据行,其中第二行包含一个嵌套表格。为了实现嵌套表格,我们使用了colspan属性,将第二行中的单元格合并为一行。
在嵌套表格中,我们使用了另一个表格类“table table-bordered table-sm”。这里,table-sm类用于设置嵌套表格的大小。
最后,我们在页面底部引入Bootstrap 5的JavaScript文件,以确保页面上的所有Bootstrap组件都能正常工作。
正文完