H5表格是指在HTML5中使用<table>
元素创建的表格。CSS(层叠样式表)用于为这些表格元素设置样式,包括边框、颜色、字体、间距等。
colspan
和rowspan
属性实现单元格的合并。以下是一个简单的H5表格CSS模板示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>H5 Table CSS Template</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>30</td>
<td>New York</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>25</td>
<td>Los Angeles</td>
</tr>
<tr>
<td>Mike Johnson</td>
<td>40</td>
<td>Chicago</td>
</tr>
</tbody>
</table>
</body>
</html>
colspan
和rowspan
属性设置错误。colspan
和rowspan
的值正确,并且合并的单元格在HTML结构中正确排列。border-collapse: collapse;
正确设置,并且没有其他样式覆盖。@media (max-width: 600px) {
table, thead, tbody, th, td, tr {
display: block;
}
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr { border: 1px solid #ccc; }
td {
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
}
td:before {
position: absolute;
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}
td:nth-of-type(1):before { content: "Name"; }
td:nth-of-type(2):before { content: "Age"; }
td:nth-of-type(3):before { content: "City"; }
}
通过以上方法,可以有效解决H5表格CSS模板中常见的问题,并实现美观且响应式的表格设计。
领取专属 10元无门槛券
手把手带您无忧上云