【html】用html+css实现银行的账户信息表格

我们先来看一看某银行的账户信息表格

我们自己也可以实现类似的效果

效果图:

大家可以看到,其实效果差不多

接下来看看我们实现的代码

源码:

html 复制代码
<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>模拟银行</title>
		<style>
			* {
				margin: 0;
				padding: 0;
				color: #3f3f3f;
			}
			
			.container {
				padding-left: 10px !important;
				padding-right: 10px !important;
			}
			
			table {
				border: 1px solid #dedede;
				display: table;
				box-sizing: border-box;
				text-indent: initial;
				border-spacing: 2px;
				border-collapse: collapse;
				width: 898px;
				height: 80px;
			}
			
			
			tr {
				
				height: 40px;
				width: 10%;
				border: none;
				background: #dddddd;
				font-size: 14px;
				color: #3f3f3f;
				font-weight: normal;
				text-align: center;
			
			}
			
			th{		
				    padding-right: 36px;
				    width: 9%;
				    height: 40px;
				    border: none;
					
			}
			tbody td{
				background-color: #fff;
			}
			tbody  td{
			    font: 14px/1.5 '微软雅黑',Arial,Helvetica,Tahoma,sans-serif;
			    border-collapse: collapse;
			    border-spacing: 0;
			    padding: 0;
			    font-size: 14px;
			    color: #3f3f3f;
			    text-align: center;
			    height: 40px;
			    border: none;	
			}
			
			tbody .tar{
				text-align: right !important;
			}
			
			.table_th_money {
			    padding-right: 36px;
			    width: 9%;
			}
			.font_money {
			    font-family: Arial;
			    font-weight: bold;
			    color: #d62f2f;
			}
			
			a{
				text-decoration: none;
			}
			a:link,a:visited
			{
				color: blue;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<table class="one_lines_table" width="100%">
				<thead>
					<tr>
						<th>开户日期</th>
						<th>类型</th>
						<th>币种</th>
						<th class="tar table_th_money">账户余额</th>
						<th class="tar table_th_money">可用余额</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>
							<script>
								formatDate('20230925')
							</script>2023-09-25
						</td>
						<td> 活期储蓄 </td>
						<td>人民币</td>
						<td class="tar"> <span class="font_money table_th_money">
								<script>
									formatAmt('629.28')
								</script>629.28
							</span> </td>
						<td class="tar"> <span class="font_money table_th_money">
								<script>
									formatAmt('629.28')
								</script>629.28
							</span> </td>
						<td> <a href="#" class="detail pr_5">明细</a>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</body>
</html>

建议和优化:

  1. 表格宽度 : 你设置了tablewidth898px,但这可能不是最灵活的解决方案,特别是当考虑到不同屏幕尺寸的响应式设计时。一个更好的做法可能是使用百分比或max-width来限制表格的最大宽度,同时允许它在较小的屏幕上缩小。

  2. 行和列的宽度 : 你为每个<tr>元素设置了width: 10%;,但实际上<tr>元素不控制列的宽度,而是<th><td>元素控制列的宽度。对于<tr>元素,你其实只需要设置height

  3. 使用border-collapse : 你已经设置了border-collapse: collapse;table元素上,这是正确的,因为它会合并相邻的单元格边框。

  4. 内边距和外边距 : .container中的padding-leftpadding-right被设置为10px,这是可以的,但请确保这符合你的整体布局和设计需求。

  5. 字体设置 : 你已经在tbody td中设置了字体相关的样式,但.font_money类也定义了字体样式。确保这些样式不会相互冲突,并且你确实需要这些额外的类。

  6. JavaScript函数 : 你需要确保formatDateformatAmt这两个JavaScript函数已经在页面的某个地方被正确定义。例如,你可能需要在<script>标签内或在外部JavaScript文件中定义它们。

  7. 表格标题的对齐 : 你已经使用.tar类来将某些列的文本对齐到右侧,这是通过text-align: right;实现的。这是正确的做法。

  8. 响应式设计: 考虑添加媒体查询(Media Queries)来优化不同屏幕尺寸下的表格布局。例如,在小屏幕上,你可能希望表格的列堆叠起来而不是水平排列。

  9. 代码组织 : 为了提高代码的可读性和可维护性,建议将CSS规则分组到更具体的类或ID下,而不是使用通配符*。此外,考虑将CSS代码移到单独的.css文件中,并链接到HTML文件。

  10. 语义化HTML : 你的HTML结构看起来是合理的,但请确保你使用的是语义化的HTML元素。例如,<thead>, <tbody>, <th>, 和 <td> 是正确的表格元素。

相关推荐
崔庆才丨静觅5 小时前
hCaptcha 验证码图像识别 API 对接教程
前端
passerby60616 小时前
完成前端时间处理的另一块版图
前端·github·web components
掘了6 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
崔庆才丨静觅6 小时前
实用免费的 Short URL 短链接 API 对接说明
前端
崔庆才丨静觅6 小时前
5分钟快速搭建 AI 平台并用它赚钱!
前端
崔庆才丨静觅7 小时前
比官方便宜一半以上!Midjourney API 申请及使用
前端
Moment7 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
崔庆才丨静觅7 小时前
刷屏全网的“nano-banana”API接入指南!0.1元/张量产高清创意图,开发者必藏
前端
剪刀石头布啊7 小时前
jwt介绍
前端
爱敲代码的小鱼7 小时前
AJAX(异步交互的技术来实现从服务端中获取数据):
前端·javascript·ajax