使用HTML表格展示商品 - 代码示例及教程
以下是一个示例的HTML代码,使用table标签来展示商品信息:
<!DOCTYPE html>
<html>
<head>
<title>商品展示</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>商品列表</h1>
<table>
<tr>
<th>商品名称</th>
<th>价格</th>
<th>库存数量</th>
</tr>
<tr>
<td>商品1</td>
<td>100</td>
<td>10</td>
</tr>
<tr>
<td>商品2</td>
<td>200</td>
<td>5</td>
</tr>
<tr>
<td>商品3</td>
<td>50</td>
<td>20</td>
</tr>
</table>
</body>
</html>
这段代码创建了一个包含商品列表的表格,其中每个商品占据一行,每个属性(商品名称、价格和库存数量)占据一列。商品列表被包含在table标签中,并使用tr标签定义行,使用th标签定义表头,使用td标签定义表格数据单元格。
CSS样式部分定义了表格的样式,包括边框样式、内边距和对齐方式。
原文地址: https://www.cveoy.top/t/topic/pKmb 著作权归作者所有。请勿转载和采集!