如何在html中定义表格的宽度和高度?



如何在html中定义表格的宽度和高度?以及如何更改该链接的颜色和字体大小(绿色覆盖字体(, 我想让页面美丽,project_list.html如下,非常感谢您的帮助:

{% extends 'base.html' %}
{% block content %}
<nav aria-label="breadcrumb">
</nav>
<h3 class="mb-3">我学习的课程列表</h3>
<div class="card">
<table class="table mb-0">
<thead>
<tr>
<th>课程序号</th>
<th>课程名称</th>
<th>部门名称</th>
<th>课程日期</th>
<th>课程时间</th>
<th></th>
</tr>
</thead>
<tbody>
{% for course in courses %}
<tr>
<td class="align-middle">{{ course.pk }}</td>
<td class="align-middle" style="word-break: break-all;"><a href="{% url 'employees:course_detail' course.pk%}">{{ course.name }}</a></td>
<td class="align-middle">{{ course.department.get_html_badge }}</td>
<td class="align-middle">{{ course.date }}</td>
<td class="align-middle">{{ course.time }}</td>
</tr>
{% empty %}
<tr>
<td class="bg-light text-center font-italic" colspan="4">目前没有你所选技能的课程。</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="card-footer">

至于宽度,我认为最简单的选择是为 thead 元素定义特定的宽度,例如

<thead>
<tr>
<th width="7%">课程序号</th>
<th width="47%">课程名称</th>
<th width="20%">部门名称</th>
<th width="10%">课程日期</th>
<th width="10%">课程时间</th>
<th width="6%"></th>
</tr>
</thead>

您可以根据生成的表格改变宽度。百分比宽度总是很难调整。

至于高度,它会相应地调整。我不建议您为行分配高度,因为如果内容的长度不同,它将无法正确调整。

至于链接颜色,我认为最简单的是:

<td class="align-middle" style="word-break: break-all;"><a href="{% url 'employees:course_detail' course.pk%}" style="color:blue;font-size:16px;">{{ course.name }}</a></td>

如果使用remem则可以将16px替换为所需的值。

使用百分比,而不是像素,例如<td height="10%">Text</td> <td width="70%">Text</td>。百分比将取决于周围的元素,您必须根据需要进行调整。

要更改表格的宽度和高度,您可以在 HTML 中使用 colgroup。要更改颜色,只需在样式元素中指定它。

<table>
<colgroup>
<col style="width:80px" />
<col style="width:80px" />
<col style="width:80px" />
</colgroup>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>

要定义表格的宽度,您可以使用<table width="400">这将更改下面给出的详细描述中的表格宽度。

https://www.w3schools.com/tags/att_table_width.asp

要更改链接的颜色,您可以使用以下内容:

<body a link="black" vlink="red"> 

这可能对你有用:(

最新更新